fix: Spanish frontend, wider columns, currency symbols, PDF download
PDF fix: - Replace session-cookie auth with HTTP Basic Auth (username:api_key) which is natively supported by Odoo 17+ report endpoints - Validate response is actually a PDF (%PDF header check) before serving - Return a descriptive Spanish error if HTTP code != 200 or body is not PDF Frontend → Spanish: - All invoice template text in Spanish (Nº Factura, Vencimiento, etc.) - All calendar/booking template text in Spanish - Payment state labels: Pendiente / Parcial / En cobro / Pagado / Anulado - "Vencida" badge for overdue invoices - Error/notice messages in Spanish across both pages Currency symbols: - Add currency_symbol() helper mapping ISO codes to symbols - EUR → €, USD → $, GBP → £, etc. (25 currencies mapped) Column widths: - Switch invoice table to table-layout:fixed with explicit column widths - col-number: 180px nowrap so reference never wraps across lines - Date/due/amount/status columns all fixed-width and nowrap - Add .woodoo-nowrap utility class Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,96 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Template: My Account – Odoo Invoices
|
||||
* Template: Mi cuenta – Facturas de Odoo
|
||||
*
|
||||
* Variables available:
|
||||
* $invoices array List of invoice records from Odoo
|
||||
* $total int Total invoice count
|
||||
* $paged int Current page
|
||||
* $num_pages int Total pages
|
||||
* Variables disponibles:
|
||||
* $invoices array Lista de facturas desde Odoo
|
||||
* $total int Total de facturas
|
||||
* $paged int Página actual
|
||||
* $num_pages int Total de páginas
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
// Enqueue frontend assets
|
||||
wp_enqueue_style( 'woodoo-frontend' );
|
||||
wp_enqueue_script( 'woodoo-frontend' );
|
||||
?>
|
||||
|
||||
<div class="woodoo-invoices">
|
||||
<h3><?php esc_html_e( 'Your Invoices', 'woodoo' ); ?></h3>
|
||||
<h3>Tus Facturas</h3>
|
||||
|
||||
<?php if ( empty( $invoices ) ) : ?>
|
||||
<p class="woodoo-empty">
|
||||
<?php esc_html_e( 'No invoices found.', 'woodoo' ); ?>
|
||||
</p>
|
||||
<p class="woodoo-empty">No se han encontrado facturas.</p>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<div class="woodoo-table-wrap">
|
||||
<table class="woodoo-table">
|
||||
<table class="woodoo-table woodoo-invoices-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php esc_html_e( 'Invoice #', 'woodoo' ); ?></th>
|
||||
<th><?php esc_html_e( 'Date', 'woodoo' ); ?></th>
|
||||
<th><?php esc_html_e( 'Due Date', 'woodoo' ); ?></th>
|
||||
<th><?php esc_html_e( 'Total', 'woodoo' ); ?></th>
|
||||
<th><?php esc_html_e( 'Balance Due', 'woodoo' ); ?></th>
|
||||
<th><?php esc_html_e( 'Status', 'woodoo' ); ?></th>
|
||||
<th><?php esc_html_e( 'Download', 'woodoo' ); ?></th>
|
||||
<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-status">Estado</th>
|
||||
<th class="col-download">PDF</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ( $invoices as $inv ) :
|
||||
$currency = is_array( $inv['currency_id'] ) ? $inv['currency_id'][1] : '';
|
||||
$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( [
|
||||
$currency_name = is_array( $inv['currency_id'] ) ? $inv['currency_id'][1] : '';
|
||||
$currency = WooDoo_Invoices::currency_symbol( $currency_name );
|
||||
$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="woodoo-inv-number">
|
||||
<?php echo esc_html( $inv['name'] ?: "INV-{$inv['id']}" ); ?>
|
||||
<td class="col-number woodoo-inv-number">
|
||||
<?php echo esc_html( $inv['name'] ?: 'FAC-' . $inv['id'] ); ?>
|
||||
</td>
|
||||
<td>
|
||||
<td class="col-date woodoo-nowrap">
|
||||
<?php echo $inv['invoice_date']
|
||||
? esc_html( date_i18n( get_option( 'date_format' ), strtotime( $inv['invoice_date'] ) ) )
|
||||
? esc_html( date_i18n( 'd/m/Y', strtotime( $inv['invoice_date'] ) ) )
|
||||
: '—'; ?>
|
||||
</td>
|
||||
<td>
|
||||
<td class="col-due woodoo-nowrap">
|
||||
<?php
|
||||
if ( $inv['invoice_date_due'] ) {
|
||||
$due_ts = strtotime( $inv['invoice_date_due'] );
|
||||
$overdue = $pay_state === 'not_paid' && $due_ts < time();
|
||||
$class = $overdue ? ' class="woodoo-overdue"' : '';
|
||||
echo '<span' . $class . '>' . // phpcs:ignore WordPress.Security.EscapeOutput
|
||||
esc_html( date_i18n( get_option( 'date_format' ), $due_ts ) ) .
|
||||
'</span>';
|
||||
if ( $overdue ) echo ' <span class="woodoo-badge woodoo-badge--red">' . esc_html__( 'Overdue', 'woodoo' ) . '</span>';
|
||||
$due_ts = strtotime( $inv['invoice_date_due'] );
|
||||
$overdue = ( $pay_state === 'not_paid' || $pay_state === 'partial' ) && $due_ts < time();
|
||||
if ( $overdue ) {
|
||||
echo '<span class="woodoo-overdue">';
|
||||
echo esc_html( date_i18n( 'd/m/Y', $due_ts ) );
|
||||
echo '</span> <span class="woodoo-badge woodoo-badge--red">Vencida</span>';
|
||||
} else {
|
||||
echo esc_html( date_i18n( 'd/m/Y', $due_ts ) );
|
||||
}
|
||||
} else {
|
||||
echo '—';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<td class="woodoo-amount">
|
||||
<?php echo esc_html( number_format_i18n( $inv['amount_total'], 2 ) . ' ' . $currency ); ?>
|
||||
<td class="col-amount woodoo-amount woodoo-nowrap">
|
||||
<?php echo esc_html( number_format( (float) $inv['amount_total'], 2, ',', '.' ) . ' ' . $currency ); ?>
|
||||
</td>
|
||||
<td class="woodoo-amount">
|
||||
<?php echo esc_html( number_format_i18n( $inv['amount_residual'], 2 ) . ' ' . $currency ); ?>
|
||||
<td class="col-balance woodoo-amount woodoo-nowrap">
|
||||
<?php echo esc_html( number_format( (float) $inv['amount_residual'], 2, ',', '.' ) . ' ' . $currency ); ?>
|
||||
</td>
|
||||
<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>
|
||||
<td class="col-download">
|
||||
<a href="<?php echo esc_url( $pdf_url ); ?>"
|
||||
class="woodoo-btn woodoo-btn--sm"
|
||||
target="_blank"
|
||||
rel="noopener">
|
||||
<?php esc_html_e( 'PDF', 'woodoo' ); ?>
|
||||
rel="noopener"
|
||||
title="Descargar factura en PDF">
|
||||
↓ PDF
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -102,7 +104,7 @@ wp_enqueue_script( 'woodoo-frontend' );
|
||||
<?php if ( $num_pages > 1 ) :
|
||||
$base_url = wc_get_account_endpoint_url( WooDoo_Invoices::ENDPOINT );
|
||||
?>
|
||||
<nav class="woodoo-pagination">
|
||||
<nav class="woodoo-pagination" aria-label="Paginación de facturas">
|
||||
<?php for ( $p = 1; $p <= $num_pages; $p++ ) : ?>
|
||||
<?php if ( $p === $paged ) : ?>
|
||||
<span class="woodoo-page-current"><?php echo esc_html( $p ); ?></span>
|
||||
|
||||
Reference in New Issue
Block a user