From add4cdc137118dcb4862f2060f9d79435e7898f8 Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Wed, 8 Apr 2026 10:08:17 +0200 Subject: [PATCH] Add Packing list template --- modules/purchase_trade/stock.py | 19 ++++++++++++++ modules/purchase_trade/tests/test_module.py | 28 +++++++++++++++++++++ modules/stock/packing_list.fodt | 6 ++--- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/modules/purchase_trade/stock.py b/modules/purchase_trade/stock.py index b997423..5744a9b 100755 --- a/modules/purchase_trade/stock.py +++ b/modules/purchase_trade/stock.py @@ -764,6 +764,25 @@ class ShipmentIn(metaclass=PoolMeta): return self.bl_date.strftime('%d-%m-%Y') return '' + @property + def report_packing_today_date(self): + Date = Pool().get('ir.date') + today = Date.today() + if not today: + return '' + return f"{today.strftime('%B')} {today.day}, {today.year}" + + @property + def report_packing_weight_unit(self): + line = self._get_report_trade_line() + unit = getattr(line, 'unit', None) if line else None + if unit: + return ( + getattr(unit, 'symbol', None) + or getattr(unit, 'rec_name', None) + or '') + return self.report_packing_invoice_qty_unit or 'KGS' + @property def report_packing_gross_weight(self): _, gross = self._get_report_weight_totals() diff --git a/modules/purchase_trade/tests/test_module.py b/modules/purchase_trade/tests/test_module.py index 50a68f9..e92d22c 100644 --- a/modules/purchase_trade/tests/test_module.py +++ b/modules/purchase_trade/tests/test_module.py @@ -638,6 +638,34 @@ class PurchaseTradeTestCase(ModuleTestCase): self.assertEqual( shipment.report_insurance_surveyor, 'SGS') + def test_shipment_packing_helpers_use_today_and_trade_unit(self): + 'packing list helpers expose today date and trade line unit' + ShipmentIn = Pool().get('stock.shipment.in') + shipment = ShipmentIn() + shipment.quantity = Decimal('1010') + shipment.unit = Mock(symbol='KGS', rec_name='KGS') + + trade_line = Mock() + trade_line.unit = Mock(symbol='MT', rec_name='MT') + lot = Mock(line=trade_line, sale_line=None) + lot.get_current_quantity = Mock(return_value=Decimal('1010')) + lot.get_current_gross_quantity = Mock(return_value=Decimal('1012')) + move = Mock(lot=lot, quantity=Decimal('0')) + shipment.incoming_moves = [move] + shipment.moves = [move] + + with patch( + 'trytond.modules.purchase_trade.stock.Pool' + ) as PoolMock: + date_model = Mock() + date_model.today.return_value = datetime.date(2026, 4, 8) + PoolMock.return_value.get.return_value = date_model + + self.assertEqual( + shipment.report_packing_today_date, 'April 8, 2026') + self.assertEqual( + shipment.report_packing_weight_unit, 'MT') + def test_sale_report_multi_line_helpers_aggregate_all_lines(self): 'sale report helpers aggregate quantity, price lines and shipment periods' Sale = Pool().get('sale.sale') diff --git a/modules/stock/packing_list.fodt b/modules/stock/packing_list.fodt index 1939efb..243cff8 100644 --- a/modules/stock/packing_list.fodt +++ b/modules/stock/packing_list.fodt @@ -1662,7 +1662,7 @@ - April 8, 2026 + <records[0].report_packing_today_date or ''> @@ -1684,9 +1684,9 @@ - Gross weight:<records[0].report_packing_gross_weight or ''>KGS + Gross weight:<records[0].report_packing_gross_weight or ''><records[0].report_packing_weight_unit or ''> - Net weight:<records[0].report_packing_net_weight or ''>KGS + Net weight:<records[0].report_packing_net_weight or ''><records[0].report_packing_weight_unit or ''>