Th qt correction
This commit is contained in:
@@ -184,6 +184,80 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
self.assertEqual(
|
||||
PurchaseLine.default_pricing_rule(), 'Default pricing rule')
|
||||
|
||||
def test_sale_line_write_updates_virtual_lot_when_theorical_qty_increases(self):
|
||||
'sale line write increases virtual lot and open lot.qt when contractual qty grows'
|
||||
SaleLine = Pool().get('sale.line')
|
||||
line = Mock(id=1, quantity_theorical=Decimal('10'))
|
||||
line.unit = Mock()
|
||||
vlot = Mock(id=99, lot_type='virtual')
|
||||
vlot.get_current_quantity_converted.return_value = Decimal('10')
|
||||
line.lots = [vlot]
|
||||
lqt = Mock(lot_quantity=Decimal('10'))
|
||||
|
||||
lot_model = Mock()
|
||||
lotqt_model = Mock()
|
||||
lotqt_model.search.return_value = [lqt]
|
||||
|
||||
with patch(
|
||||
'trytond.modules.purchase_trade.sale.Pool'
|
||||
) as PoolMock, patch(
|
||||
'trytond.modules.purchase_trade.sale.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
|
||||
|
||||
SaleLine.write([line], {'quantity_theorical': Decimal('12')})
|
||||
|
||||
self.assertEqual(lqt.lot_quantity, Decimal('12'))
|
||||
vlot.set_current_quantity.assert_called_once_with(
|
||||
Decimal('12'), Decimal('12'), 1)
|
||||
lot_model.save.assert_called()
|
||||
lotqt_model.save.assert_called()
|
||||
|
||||
def test_sale_line_write_blocks_theorical_qty_decrease_when_no_open_quantity(self):
|
||||
'sale line write blocks contractual qty decrease when open lot.qt is insufficient'
|
||||
SaleLine = Pool().get('sale.line')
|
||||
line = Mock(id=2, quantity_theorical=Decimal('10'))
|
||||
vlot = Mock(id=100, lot_type='virtual')
|
||||
vlot.get_current_quantity_converted.return_value = Decimal('10')
|
||||
line.lots = [vlot]
|
||||
lqt = Mock(lot_quantity=Decimal('1'))
|
||||
|
||||
lot_model = Mock()
|
||||
lotqt_model = Mock()
|
||||
lotqt_model.search.return_value = [lqt]
|
||||
|
||||
with patch(
|
||||
'trytond.modules.purchase_trade.sale.Pool'
|
||||
) as PoolMock, patch(
|
||||
'trytond.modules.purchase_trade.sale.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
|
||||
|
||||
with self.assertRaises(UserError):
|
||||
SaleLine.write([line], {'quantity_theorical': Decimal('8')})
|
||||
|
||||
def test_party_execution_achieved_percent_uses_real_area_statistics(self):
|
||||
'party execution achieved percent reflects the controller share in its area'
|
||||
PartyExecution = Pool().get('party.execution')
|
||||
|
||||
Reference in New Issue
Block a user