From cda8b4067b87ad64ce8708dee54d6db345e2a4e4 Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Thu, 16 Jul 2026 12:22:51 +0200 Subject: [PATCH] Bug Add physical lots --- modules/purchase_trade/fee.py | 44 ++++++++++++++------- modules/purchase_trade/tests/test_module.py | 31 +++++++++++++++ 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/modules/purchase_trade/fee.py b/modules/purchase_trade/fee.py index eb0eef9..c5522ca 100755 --- a/modules/purchase_trade/fee.py +++ b/modules/purchase_trade/fee.py @@ -290,21 +290,35 @@ class Fee(ModelSQL,ModelView): else: return self.unit - def get_lots(self, name): - logger.info("GET_LOTS_LINE:%s",self.line) - logger.info("GET_LOTS_SHIPMENT_IN:%s",self.shipment_in) - Lot = Pool().get('lot.lot') - if self.line: - return self.line.lots - if self.shipment_in: - lots = Lot.search([('lot_shipment_in','=',self.shipment_in.id)]) - logger.info("LOTSDOMAIN:%s",lots) - if lots: - return lots + [lots[0].getVlot_p()] - if self.shipment_internal: - return Lot.search([('lot_shipment_internal','=',self.shipment_internal.id)]) - if self.shipment_out: - return Lot.search([('lot_shipment_out','=',self.shipment_out.id)]) + def get_lots(self, name): + logger.info("GET_LOTS_LINE:%s",self.line) + logger.info("GET_LOTS_SHIPMENT_IN:%s",self.shipment_in) + Lot = Pool().get('lot.lot') + if self.line: + return self.line.lots + if self.shipment_in: + LotQt = Pool().get('lot.qt') + lots = Lot.search([('lot_shipment_in','=',self.shipment_in.id)]) + logger.info("LOTSDOMAIN:%s",lots) + domain_lots = [] + seen = set() + for lot in lots: + lot_id = getattr(lot, 'id', None) + if lot_id not in seen: + domain_lots.append(lot) + seen.add(lot_id) + for lqt in LotQt.search(['lot_shipment_in','=',self.shipment_in.id]): + lot = getattr(lqt, 'lot_p', None) + lot_id = getattr(lot, 'id', None) + if lot and lot_id not in seen: + domain_lots.append(lot) + seen.add(lot_id) + if domain_lots: + return domain_lots + if self.shipment_internal: + return Lot.search([('lot_shipment_internal','=',self.shipment_internal.id)]) + if self.shipment_out: + return Lot.search([('lot_shipment_out','=',self.shipment_out.id)]) return Lot.search(['id','>',0]) diff --git a/modules/purchase_trade/tests/test_module.py b/modules/purchase_trade/tests/test_module.py index bed2e1d..088a08b 100644 --- a/modules/purchase_trade/tests/test_module.py +++ b/modules/purchase_trade/tests/test_module.py @@ -2332,6 +2332,37 @@ class PurchaseTradeTestCase(ModuleTestCase): self.assertEqual(fee.quantity, Decimal('40.00000')) save.assert_called_once_with([fee]) + def test_shipment_fee_lot_domain_keeps_open_virtual_lots(self): + 'shipment fee lot domain keeps virtual lots after partial physical add' + Fee = Pool().get('fee.fee') + fee = Fee() + fee.line = None + fee.sale_line = None + fee.shipment_in = Mock(id=7) + fee.shipment_internal = None + fee.shipment_out = None + physical = Mock(id=2599, lot_type='physic') + virtual_a = Mock(id=2666, lot_type='virtual') + virtual_b = Mock(id=2623, lot_type='virtual') + physical.getVlot_p.return_value = virtual_a + Lot = Mock() + Lot.search.return_value = [physical] + LotQt = Mock() + LotQt.search.return_value = [ + Mock(lot_p=virtual_a), + Mock(lot_p=virtual_b), + ] + + with patch('trytond.modules.purchase_trade.fee.Pool') as PoolMock: + PoolMock.return_value.get.side_effect = lambda name: { + 'lot.lot': Lot, + 'lot.qt': LotQt, + }[name] + + lots = fee.get_lots(None) + + self.assertEqual(lots, [physical, virtual_a, virtual_b]) + def test_fee_ppack_auto_sync_keeps_auto_quantity(self): 'per packing auto fee keeps the on-change quantity on save' Fee = Pool().get('fee.fee')