Plan to transport

This commit is contained in:
2026-06-06 19:46:51 +02:00
parent b74389f9a6
commit d659f14e12
6 changed files with 497 additions and 57 deletions

View File

@@ -89,6 +89,108 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(
Valuation.get_totals(), (Decimal('42.50'), Decimal(0)))
def test_lotqt_plan_to_transport_splits_source_quantity(self):
'planning transport creates an isolated lot.qt split'
LotQt = lot_module.LotQt
source = Mock(
lot_p=Mock(id=1),
lot_s=Mock(id=2),
lot_quantity=Decimal('500'),
lot_unit=Mock(id=3),
lot_av='available',
lot_status='forecast',
lot_visible=True,
)
source.has_shipment.return_value = False
source.is_planned_transport.return_value = False
values = {
'planned_from_location': 10,
'planned_to_location': 20,
'planned_transport_type': 'truck',
'planned_from_date': datetime.date(2026, 7, 1),
'planned_to_date': datetime.date(2026, 7, 5),
'planned_note': 'Early planning',
}
with patch.object(LotQt, 'save') as save, patch.object(
LotQt, 'create') as create:
LotQt.plan_to_transport(source, Decimal('125'), values)
self.assertEqual(source.lot_quantity, Decimal('375.00000'))
save.assert_called_once_with([source])
create.assert_called_once_with([{
'lot_p': 1,
'lot_s': 2,
'lot_quantity': Decimal('125.00000'),
'lot_unit': 3,
'lot_av': 'available',
'lot_status': 'forecast',
'lot_visible': True,
'planned_from_location': 10,
'planned_to_location': 20,
'planned_transport_type': 'truck',
'planned_from_date': datetime.date(2026, 7, 1),
'planned_to_date': datetime.date(2026, 7, 5),
'planned_note': 'Early planning',
}])
def test_lotqt_plan_to_transport_preserves_sale_only_sign(self):
'planning a sale-only lot.qt keeps the negative quantity direction'
LotQt = lot_module.LotQt
source = Mock(
lot_p=None,
lot_s=Mock(id=2),
lot_quantity=Decimal('-500'),
lot_unit=Mock(id=3),
lot_av='available',
lot_status='forecast',
lot_visible=True,
)
source.has_shipment.return_value = False
source.is_planned_transport.return_value = False
with patch.object(LotQt, 'save'), patch.object(
LotQt, 'create') as create:
LotQt.plan_to_transport(
source, Decimal('125'),
{'planned_transport_type': 'vessel'})
self.assertEqual(source.lot_quantity, Decimal('-375.00000'))
self.assertEqual(
create.call_args[0][0][0]['lot_quantity'],
Decimal('-125.00000'))
self.assertEqual(create.call_args[0][0][0]['lot_p'], None)
self.assertEqual(create.call_args[0][0][0]['lot_s'], 2)
def test_lotqt_cancel_transport_plan_merges_matching_open_line(self):
'cancelling a transport plan returns quantity to the open lot.qt'
LotQt = lot_module.LotQt
planned = Mock(
lot_p=Mock(id=1),
lot_s=None,
lot_quantity=Decimal('125'),
lot_unit=Mock(id=3),
lot_av='available',
lot_status='forecast',
lot_visible=True,
)
planned.has_shipment.return_value = False
planned.is_planned_transport.return_value = True
target = Mock(lot_quantity=Decimal('375'))
with patch.object(
LotQt, 'search', return_value=[target]) as search, patch.object(
LotQt, 'save') as save, patch.object(
LotQt, 'create') as create, patch.object(
LotQt, 'delete') as delete:
LotQt.cancel_transport_plan(planned)
search.assert_called_once()
self.assertEqual(target.lot_quantity, Decimal('500'))
save.assert_called_once_with([target])
create.assert_not_called()
delete.assert_called_once_with([planned])
@with_transaction()
def test_get_mtm_applies_component_ratio_as_percentage(self):
'get_mtm treats component ratio as a percentage'