Th qt modification

This commit is contained in:
2026-05-01 09:16:07 +02:00
parent 83aa474073
commit e03dee7def
5 changed files with 194 additions and 84 deletions

View File

@@ -1061,7 +1061,7 @@ class PurchaseTradeTestCase(ModuleTestCase):
lot_model = Mock()
lotqt_model = Mock()
lotqt_model.search.return_value = [lqt]
lotqt_model.search.side_effect = [[lqt], []]
with patch(
'trytond.modules.purchase_trade.sale.Pool'
@@ -1097,10 +1097,11 @@ class PurchaseTradeTestCase(ModuleTestCase):
vlot.get_current_quantity_converted.return_value = Decimal('10')
line.lots = [vlot]
lqt = Mock(lot_quantity=Decimal('1'))
matched_lqt = Mock(lot_quantity=Decimal('9'))
lot_model = Mock()
lotqt_model = Mock()
lotqt_model.search.return_value = [lqt]
lotqt_model.search.side_effect = [[lqt], [matched_lqt]]
with patch(
'trytond.modules.purchase_trade.sale.Pool'
@@ -1123,6 +1124,48 @@ class PurchaseTradeTestCase(ModuleTestCase):
with self.assertRaises(UserError):
SaleLine.write([line], {'quantity_theorical': Decimal('8')})
def test_purchase_line_write_syncs_open_lot_qt_with_physical_lots(self):
'purchase line write keeps open lot.qt net of existing physical lots'
PurchaseLine = Pool().get('purchase.line')
line = Mock(id=4, quantity_theorical=Decimal('10000'))
line.unit = Mock()
vlot = Mock(id=102, lot_type='virtual')
vlot.get_current_quantity_converted.return_value = Decimal('10000')
physical = Mock(lot_type='physic')
physical.get_current_quantity_converted.return_value = Decimal('10000')
line.lots = [vlot, physical]
lqt = Mock(lot_quantity=Decimal('10000'))
lot_model = Mock()
lotqt_model = Mock()
lotqt_model.search.side_effect = [[lqt], []]
with patch(
'trytond.modules.purchase_trade.purchase.Pool'
) as PoolMock, patch(
'trytond.modules.purchase_trade.purchase.super'
) as super_mock:
PoolMock.return_value.get.side_effect = lambda name: {
'lot.lot': lot_model,
'lot.qt': lotqt_model,
}[name]
def fake_super_write(*args):
for records, values in zip(args[::2], args[1::2]):
if 'quantity_theorical' in values:
for record in records:
record.quantity_theorical = values['quantity_theorical']
super_mock.return_value.write.side_effect = fake_super_write
PurchaseLine.write(
[line], {'quantity_theorical': Decimal('20000')})
self.assertEqual(lqt.lot_quantity, Decimal('10000'))
vlot.set_current_quantity.assert_not_called()
lot_model.save.assert_not_called()
lotqt_model.save.assert_not_called()
def test_purchase_line_write_initial_theorical_qty_does_not_double_open_lot(self):
'purchase line write does not re-add quantity when initializing contractual qty'
PurchaseLine = Pool().get('purchase.line')