feat: invoice email resend, smaller table, column cleanup

Email resend (replaces broken PDF download):
- New AJAX action woodoo_send_invoice_email
- Finds Odoo invoice email template via ir.model.data (cached 24h)
  with fallback search on mail.template by model
- Calls mail.template.send_mail([template_id], invoice_id, force_send=True)
  via authenticated JSON-RPC — triggers Odoo to email the invoice
- Inline success/error row appears below the invoice row, auto-hides 6s
- Button shows "Enviando…" spinner state, resets on failure

Table columns:
- Remove "Saldo pendiente" column (was amount_residual)
- Rename "Total" → "Importe"
- min-width reduced to 700px now that there are 6 columns
- Font size reduced to .8rem for denser display

JS restructured so invoice email handler always runs (no early exit),
calendar handler only runs when WooDooCalendar data is present.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Malin
2026-04-01 17:43:39 +02:00
parent d1597731c5
commit c05433689e
4 changed files with 221 additions and 167 deletions

View File

@@ -13,6 +13,10 @@ defined( 'ABSPATH' ) || exit;
wp_enqueue_style( 'woodoo-frontend' );
wp_enqueue_script( 'woodoo-frontend' );
wp_localize_script( 'woodoo-frontend', 'WooDooInvoices', [
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'woodoo_invoice_email' ),
] );
?>
<div class="woodoo-invoices">
@@ -30,10 +34,9 @@ wp_enqueue_script( 'woodoo-frontend' );
<th class="col-number">Nº Factura</th>
<th class="col-date">Fecha</th>
<th class="col-due">Vencimiento</th>
<th class="col-amount">Total</th>
<th class="col-balance">Saldo pendiente</th>
<th class="col-amount">Importe</th>
<th class="col-status">Estado</th>
<th class="col-download">PDF</th>
<th class="col-action">Envío</th>
</tr>
</thead>
<tbody>
@@ -43,11 +46,6 @@ wp_enqueue_script( 'woodoo-frontend' );
$pay_state = $inv['payment_state'] ?? 'not_paid';
$badge_class = WooDoo_Invoices::payment_state_class( $pay_state );
$badge_label = WooDoo_Invoices::payment_state_label( $pay_state );
$pdf_url = add_query_arg( [
'action' => 'woodoo_invoice_pdf',
'invoice_id' => $inv['id'],
'nonce' => wp_create_nonce( 'woodoo_invoice_pdf' ),
], admin_url( 'admin-ajax.php' ) );
?>
<tr>
<td class="col-number woodoo-inv-number">
@@ -78,22 +76,18 @@ wp_enqueue_script( 'woodoo-frontend' );
<td class="col-amount woodoo-amount woodoo-nowrap">
<?php echo esc_html( number_format( (float) $inv['amount_total'], 2, ',', '.' ) . ' ' . $currency ); ?>
</td>
<td class="col-balance woodoo-amount woodoo-nowrap">
<?php echo esc_html( number_format( (float) $inv['amount_residual'], 2, ',', '.' ) . ' ' . $currency ); ?>
</td>
<td class="col-status woodoo-nowrap">
<span class="woodoo-badge <?php echo esc_attr( $badge_class ); ?>">
<?php echo esc_html( $badge_label ); ?>
</span>
</td>
<td class="col-download">
<a href="<?php echo esc_url( $pdf_url ); ?>"
class="woodoo-btn woodoo-btn--sm"
target="_blank"
rel="noopener"
title="Descargar factura en PDF">
↓ PDF
</a>
<td class="col-action">
<button type="button"
class="woodoo-btn woodoo-btn--sm woodoo-send-invoice"
data-id="<?php echo esc_attr( $inv['id'] ); ?>"
title="Reenviar factura por correo electrónico">
✉ Reenviar
</button>
</td>
</tr>
<?php endforeach; ?>