Bug Add physical lots

This commit is contained in:
2026-07-16 12:22:51 +02:00
parent 728e2c7d60
commit cda8b4067b
2 changed files with 60 additions and 15 deletions

View File

@@ -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])

View File

@@ -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')