From cf7aa7f5b59dd831b578db1e2963d60c306107f7 Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Tue, 23 Jun 2026 15:28:11 +0200 Subject: [PATCH] Lot invoicing + Fee padding --- modules/purchase_trade/lot.py | 21 ++++++++++++++++----- modules/purchase_trade/tests/test_module.py | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/modules/purchase_trade/lot.py b/modules/purchase_trade/lot.py index 80468e9..ab48007 100755 --- a/modules/purchase_trade/lot.py +++ b/modules/purchase_trade/lot.py @@ -4767,7 +4767,7 @@ class LotInvoice(Wizard): val['fee_quantity'] = f.quantity val['fee_price'] = f.price val['fee_unit'] = purchase_line.unit.id - val['fee_amount'] = f.amount + val['fee_amount'] = self._fee_display_amount(f, act) val['fee_landed_cost'] = f.fee_landed_cost fee_pur.append(val) if line: @@ -4796,7 +4796,7 @@ class LotInvoice(Wizard): val['fee_quantity'] = f.quantity val['fee_price'] = f.price val['fee_unit'] = current_sale_line.unit.id - val['fee_amount'] = f.amount + val['fee_amount'] = self._fee_display_amount(f, act) val['fee_landed_cost'] = f.fee_landed_cost fee_sale.append(val) if sale_line: @@ -4818,9 +4818,20 @@ class LotInvoice(Wizard): 'pp_pur': pp_pur, 'fee_sale': fee_sale, 'pp_sale': pp_sale, - 'action': act - } - + 'action': act + } + + @staticmethod + def _fee_display_amount(fee, action): + if ( + action == 'final' + and getattr(fee, 'state', None) == 'invoiced' + and getattr(fee, 'add_padding', False)): + with Transaction().set_context( + _purchase_trade_ignore_fee_padding=True): + return fee.amount + return fee.amount + def transition_invoicing(self): Lot = Pool().get('lot.lot') Purchase = Pool().get('purchase.purchase') diff --git a/modules/purchase_trade/tests/test_module.py b/modules/purchase_trade/tests/test_module.py index 4196d44..8b62e1f 100644 --- a/modules/purchase_trade/tests/test_module.py +++ b/modules/purchase_trade/tests/test_module.py @@ -3402,6 +3402,25 @@ class PurchaseTradeTestCase(ModuleTestCase): self.assertEqual(fee_line.fee_quantity, Decimal('5')) self.assertEqual(fee_line.fee_amount, Decimal('10.00')) + def test_lot_invoice_default_final_fee_display_ignores_padding(self): + 'initial final fee display reads amount without padding' + class FeeStub: + state = 'invoiced' + add_padding = True + + @property + def amount(self): + if Transaction().context.get( + '_purchase_trade_ignore_fee_padding'): + return Decimal('14970') + return Decimal('14985') + + fee = FeeStub() + + self.assertEqual( + lot_module.LotInvoice._fee_display_amount(fee, 'final'), + Decimal('14970')) + def test_fee_get_non_cog_returns_zero_without_move_lines(self): 'fee non-cog amount is zero before any accounting move line exists' fee = fee_module.Fee()