From 58cd66e5438479f934cb95b5546394e0b230c713 Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Thu, 2 Apr 2026 16:31:05 +0200 Subject: [PATCH] 02.04.26 --- modules/purchase_trade/invoice.py | 18 +----------------- modules/purchase_trade/tests/test_module.py | 12 +++--------- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/modules/purchase_trade/invoice.py b/modules/purchase_trade/invoice.py index fe0ed3a..3ef1d8d 100644 --- a/modules/purchase_trade/invoice.py +++ b/modules/purchase_trade/invoice.py @@ -377,31 +377,15 @@ class Invoice(metaclass=PoolMeta): def report_nb_bale(self): lots = self._get_report_invoice_lots() if lots: - Uom = Pool().get('product.uom') - line = self._get_report_invoice_line() or self._get_report_trade_line() - invoice_unit = getattr(line, 'unit', None) if line else None - net = Decimal(str(self.report_net or 0)) total_packages = Decimal(0) - total_weight = Decimal(0) package_unit = None for lot in lots: if getattr(lot, 'lot_qt', None): total_packages += Decimal(str(lot.lot_qt or 0)) if not package_unit and getattr(lot, 'lot_unit', None): package_unit = lot.lot_unit - lot_quantity = Decimal(str(getattr(lot, 'lot_quantity', 0) or 0)) - lot_unit_line = getattr(lot, 'lot_unit_line', None) - if lot_quantity and lot_unit_line and invoice_unit: - total_weight += Decimal(str( - Uom.compute_qty( - lot_unit_line, float(lot_quantity), invoice_unit, - round=False) or 0)) if total_packages: - package_qty = total_packages - if total_weight and net: - package_qty = ( - net / (total_weight / total_packages)) - package_qty = package_qty.quantize( + package_qty = total_packages.quantize( Decimal('1'), rounding=ROUND_HALF_UP) if package_qty: label = self._format_report_package_label(package_unit) diff --git a/modules/purchase_trade/tests/test_module.py b/modules/purchase_trade/tests/test_module.py index 15110b0..075a9c5 100644 --- a/modules/purchase_trade/tests/test_module.py +++ b/modules/purchase_trade/tests/test_module.py @@ -333,8 +333,8 @@ class PurchaseTradeTestCase(ModuleTestCase): self.assertEqual(invoice.report_net, Decimal('800')) - def test_invoice_report_nb_bale_uses_linked_lot_packaging(self): - 'invoice reports packaging from linked physical lots with signed prorata' + def test_invoice_report_nb_bale_uses_linked_lot_quantity_only(self): + 'invoice reports packaging from linked physical lots using lot_qt only' Invoice = Pool().get('account.invoice') line = Mock(type='line', quantity=Decimal('-15')) @@ -353,17 +353,11 @@ class PurchaseTradeTestCase(ModuleTestCase): ) sale_line.lots = [lot] sale = Mock(lines=[sale_line]) - uom_model = Mock() - uom_model.compute_qty.return_value = Decimal('2000') invoice = Invoice() invoice.sales = [sale] invoice.lines = [line] - with patch( - 'trytond.modules.purchase_trade.invoice.Pool' - ) as PoolMock: - PoolMock.return_value.get.return_value = uom_model - self.assertEqual(invoice.report_nb_bale, 'NB BALES: -5') + self.assertEqual(invoice.report_nb_bale, 'NB BALES: 700') def test_invoice_report_positive_rate_lines_keep_positive_components(self): 'invoice final note pricing section keeps only positive component lines'