From 227a6c14a8ed7cb096a39cc5a27ff3e0124424df Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Fri, 19 Jun 2026 08:34:29 +0200 Subject: [PATCH] Commssion DN/CN --- .../commission__ict_final.fodt | 6 ++--- modules/purchase_trade/invoice.py | 27 +++++++++++++++++++ modules/purchase_trade/tests/test_module.py | 23 ++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/modules/account_invoice/commission__ict_final.fodt b/modules/account_invoice/commission__ict_final.fodt index 5e1d2ad..235e620 100644 --- a/modules/account_invoice/commission__ict_final.fodt +++ b/modules/account_invoice/commission__ict_final.fodt @@ -3746,7 +3746,7 @@ - <invoice.report_note_title.upper()> N. <invoice.number> + <invoice.report_commission_note_title.upper()> N. <invoice.number> INVOICE N. <invoice.reference or invoice.report_proforma_invoice_number or ''> @@ -3864,13 +3864,13 @@ - TOTAL DUE TO YOU + <invoice.report_commission_due_label> <invoice.currency.name> - <format_number(invoice.total_amount, invoice.party.lang, digits=invoice.currency.digits)> + <invoice.report_commission_note_total_display> diff --git a/modules/purchase_trade/invoice.py b/modules/purchase_trade/invoice.py index d54514c..85651a9 100644 --- a/modules/purchase_trade/invoice.py +++ b/modules/purchase_trade/invoice.py @@ -731,6 +731,33 @@ class Invoice(metaclass=PoolMeta): return self._get_report_commission_value( 'report_commission_total_display') + def _get_report_commission_amount(self): + fee = self._get_report_commission_fee() + if fee and hasattr(fee, 'get_amount'): + return fee.get_amount() + return self.total_amount or 0 + + @property + def report_commission_note_title(self): + amount = Decimal(str(self._get_report_commission_amount() or 0)) + if amount < 0: + return 'Credit Note' + return 'Debit Note' + + @property + def report_commission_due_label(self): + amount = Decimal(str(self._get_report_commission_amount() or 0)) + if amount < 0: + return 'TOTAL DUE TO US' + return 'TOTAL DUE TO YOU' + + @property + def report_commission_note_total_display(self): + amount = self._get_report_commission_amount() + return self._format_report_number( + abs(Decimal(str(amount or 0))), digits='0.01', + strip_trailing_zeros=False) + def _get_report_commission_address_for(self, kind): trade = self._get_report_commission_trade_for(kind) return getattr(trade, 'report_address', '') or '' diff --git a/modules/purchase_trade/tests/test_module.py b/modules/purchase_trade/tests/test_module.py index 7064823..dbc2893 100644 --- a/modules/purchase_trade/tests/test_module.py +++ b/modules/purchase_trade/tests/test_module.py @@ -7446,6 +7446,29 @@ class PurchaseTradeTestCase(ModuleTestCase): debit.total_amount = Decimal('-10') self.assertEqual(debit.report_note_title, 'Debit Note') + def test_invoice_commission_note_uses_company_to_broker_direction(self): + 'commission note title follows company to broker correction direction' + Invoice = Pool().get('account.invoice') + + credit = Invoice() + credit.total_amount = Decimal('-79.37') + self.assertEqual(credit.report_commission_note_title, 'Credit Note') + self.assertEqual(credit.report_commission_due_label, 'TOTAL DUE TO US') + + debit = Invoice() + debit.total_amount = Decimal('79.37') + self.assertEqual(debit.report_commission_note_title, 'Debit Note') + self.assertEqual(debit.report_commission_due_label, 'TOTAL DUE TO YOU') + + def test_invoice_commission_note_total_is_absolute(self): + 'commission note total is displayed without the accounting sign' + Invoice = Pool().get('account.invoice') + + invoice = Invoice() + invoice.total_amount = Decimal('-79.37') + + self.assertEqual(invoice.report_commission_note_total_display, '79.37') + def test_invoice_report_net_sums_signed_invoice_lines(self): 'invoice report net uses the signed differential from invoice lines' Invoice = Pool().get('account.invoice')