Remove physical lot for Planned
This commit is contained in:
@@ -494,6 +494,143 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
Lot.assert_lines_quantity_consistency.assert_called_once_with([
|
||||
lot.line])
|
||||
|
||||
def test_lot_unship_restores_planned_open_quantity(self):
|
||||
'unlinking a planned scheduled lot.qt returns it to planned'
|
||||
wizard = lot_module.LotUnship()
|
||||
record = Mock(
|
||||
id=10000007,
|
||||
r_lot_type='virtual',
|
||||
)
|
||||
wizard.records = [record]
|
||||
purchase_line = Mock()
|
||||
sale_line = Mock()
|
||||
lot = Mock(line=purchase_line)
|
||||
sale_lot = Mock(sale_line=sale_line)
|
||||
lqt = Mock(
|
||||
lot_quantity=Decimal('40'),
|
||||
lot_p=lot,
|
||||
lot_s=sale_lot,
|
||||
lot_shipment_origin='stock.shipment.in,12',
|
||||
)
|
||||
lqt.is_planned_transport.return_value = True
|
||||
Lot = Mock()
|
||||
Lot.return_value = Mock()
|
||||
Lot.skip_quantity_consistency.return_value.__enter__ = Mock()
|
||||
Lot.skip_quantity_consistency.return_value.__exit__ = Mock()
|
||||
LotQt = Mock()
|
||||
LotQt.return_value = lqt
|
||||
Move = Mock()
|
||||
|
||||
pool = Mock()
|
||||
pool.get.side_effect = [Lot, LotQt, Move]
|
||||
with patch('trytond.modules.purchase_trade.lot.Pool',
|
||||
return_value=pool):
|
||||
state = wizard.transition_start()
|
||||
|
||||
self.assertEqual(state, 'end')
|
||||
lot.updateVirtualPart.assert_called_once_with(
|
||||
Decimal('-40'), 'stock.shipment.in,12', sale_lot, 'both')
|
||||
LotQt.restore_planned_open_quantity.assert_called_once_with(
|
||||
lqt, Decimal('40'))
|
||||
lot.createVirtualPart.assert_not_called()
|
||||
Lot.assert_lines_quantity_consistency.assert_called_once_with([
|
||||
purchase_line, sale_line])
|
||||
|
||||
def test_add_physical_lots_requires_linked_transport(self):
|
||||
'physical lots can only be added from a scheduled quantity'
|
||||
LotQt = Pool().get('lot.qt')
|
||||
lqt = Mock()
|
||||
lqt.has_shipment.return_value = False
|
||||
|
||||
with self.assertRaises(UserError):
|
||||
LotQt.add_physical_lots(lqt, [])
|
||||
|
||||
def test_add_physical_lot_copies_planned_transport_memory(self):
|
||||
'physical lots keep planned transport fields from lot.qt'
|
||||
LotQt = Pool().get('lot.qt')
|
||||
lqt = LotQt()
|
||||
planned_from = Mock()
|
||||
planned_to = Mock()
|
||||
purchase_line = Mock(product=Mock(), fees=[])
|
||||
lqt.lot_p = Mock(line=purchase_line)
|
||||
lqt.lot_s = None
|
||||
lqt.lot_shipment_in = Mock(fees=[])
|
||||
lqt.lot_shipment_internal = None
|
||||
lqt.lot_shipment_out = None
|
||||
lqt.planned_from_location = planned_from
|
||||
lqt.planned_to_location = planned_to
|
||||
lqt.planned_transport_type = 'truck'
|
||||
lqt.planned_from_date = datetime.date(2026, 6, 15)
|
||||
lqt.planned_to_date = datetime.date(2026, 6, 20)
|
||||
lqt.planned_note = 'Gate 4'
|
||||
physical_input = Mock(
|
||||
lot_qt=Decimal('1'),
|
||||
lot_unit=Mock(),
|
||||
lot_unit_line=Mock(),
|
||||
lot_quantity=Decimal('40'),
|
||||
lot_gross_quantity=Decimal('41'),
|
||||
lot_premium=Decimal('0'),
|
||||
lot_chunk_key=None,
|
||||
)
|
||||
newlot = Mock()
|
||||
newlot.line = purchase_line
|
||||
newlot.sale_line = None
|
||||
newlot.set_current_quantity = Mock()
|
||||
newlot.get_current_quantity_converted.return_value = Decimal('40')
|
||||
Lot = Mock()
|
||||
Lot.return_value = newlot
|
||||
FeeLots = Mock()
|
||||
Purchase = Mock()
|
||||
|
||||
pool = Mock()
|
||||
pool.get.side_effect = [Lot, FeeLots, Purchase]
|
||||
with patch('trytond.modules.purchase_trade.lot.Pool',
|
||||
return_value=pool):
|
||||
lot, _ = lqt.add_physical_lot(physical_input)
|
||||
|
||||
self.assertIs(lot.planned_from_location, planned_from)
|
||||
self.assertIs(lot.planned_to_location, planned_to)
|
||||
self.assertEqual(lot.planned_transport_type, 'truck')
|
||||
self.assertEqual(lot.planned_from_date, datetime.date(2026, 6, 15))
|
||||
self.assertEqual(lot.planned_to_date, datetime.date(2026, 6, 20))
|
||||
self.assertEqual(lot.planned_note, 'Gate 4')
|
||||
|
||||
def test_remove_physical_lot_restores_planned_scheduled_quantity(self):
|
||||
'removing a planned physical lot restores the planned scheduled lot.qt'
|
||||
wizard = lot_module.LotRemove()
|
||||
wizard.records = [Mock(id=2014)]
|
||||
quantity = Decimal('40')
|
||||
lot_s = Mock()
|
||||
lot = Mock(
|
||||
move=None,
|
||||
lot_shipment_origin='stock.shipment.in,12',
|
||||
lot_shipment_in=None,
|
||||
lot_shipment_internal=None,
|
||||
lot_shipment_out=None,
|
||||
)
|
||||
lot.get_current_quantity_converted.return_value = quantity
|
||||
lot.getVlot_s.return_value = lot_s
|
||||
lot.sale_line = Mock()
|
||||
lot.is_planned_transport.return_value = True
|
||||
Lot = Mock()
|
||||
Lot.return_value = lot
|
||||
LotQt = Mock()
|
||||
Move = Mock()
|
||||
Warning = Mock()
|
||||
Warning.check.return_value = False
|
||||
|
||||
pool = Mock()
|
||||
pool.get.side_effect = [Lot, LotQt, Move, Warning]
|
||||
with patch('trytond.modules.purchase_trade.lot.Pool',
|
||||
return_value=pool):
|
||||
state = wizard.transition_start()
|
||||
|
||||
self.assertEqual(state, 'end')
|
||||
LotQt.restore_planned_scheduled_quantity.assert_called_once_with(
|
||||
lot, quantity, lot_s, 'stock.shipment.in,12')
|
||||
lot.updateVirtualPart.assert_not_called()
|
||||
Lot.delete.assert_called_once_with([lot])
|
||||
|
||||
def test_lot_shipping_scheduled_lotqt_keeps_planned_locations(self):
|
||||
'scheduled lot.qt keeps the planned from and to locations'
|
||||
wizard = lot_module.LotShipping()
|
||||
|
||||
Reference in New Issue
Block a user