From 126225ea6aa3ab91aea4ddd333dc417c899bc21e Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Sun, 7 Jun 2026 07:41:33 +0200 Subject: [PATCH] Link to transport --- modules/purchase_trade/lot.py | 10 ++++------ modules/purchase_trade/tests/test_module.py | 14 +++++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/purchase_trade/lot.py b/modules/purchase_trade/lot.py index 6126ff6..18144da 100755 --- a/modules/purchase_trade/lot.py +++ b/modules/purchase_trade/lot.py @@ -2958,7 +2958,7 @@ class LotShipping(Wizard): 'lot.shipping.start', 'purchase_trade.shipping_view_form', [ Button("Cancel", 'end', 'tryton-cancel'), - Button("Create shipment", 'create_shipment', 'tryton-add'), + Button("New shipment & link", 'create_shipment', 'tryton-add'), Button("Link", 'shipping', 'tryton-ok', default=True), ]) @@ -2972,8 +2972,6 @@ class LotShipping(Wizard): def default_ship(self, fields): values = {} - if getattr(self, '_created_shipment_in', None): - values['shipment_in'] = self._created_shipment_in if len(self.records) != 1: return values record = self.records[0] @@ -3017,10 +3015,10 @@ class LotShipping(Wizard): def transition_create_shipment(self): ShipmentIn = Pool().get('stock.shipment.in') if self.ship.shipment_in: - return 'ship' + return self.transition_shipping() shipment, = ShipmentIn.create([self._shipment_in_create_values()]) - self._created_shipment_in = shipment.id - return 'ship' + self.ship.shipment_in = shipment + return self.transition_shipping() def transition_shipping(self): Lot = Pool().get('lot.lot') diff --git a/modules/purchase_trade/tests/test_module.py b/modules/purchase_trade/tests/test_module.py index 31d652d..7109e2f 100644 --- a/modules/purchase_trade/tests/test_module.py +++ b/modules/purchase_trade/tests/test_module.py @@ -219,8 +219,8 @@ class PurchaseTradeTestCase(ModuleTestCase): 'planned_to_location': 20, }) - def test_lot_shipping_create_shipment_uses_planned_locations(self): - 'link to transport creates shipment in from planned locations' + def test_lot_shipping_create_shipment_links_planned_locations(self): + 'link to transport creates shipment in and links planned locations' wizard = lot_module.LotShipping() supplier = Mock(id=30) created_shipment = Mock(id=40) @@ -236,15 +236,19 @@ class PurchaseTradeTestCase(ModuleTestCase): with patch('trytond.modules.purchase_trade.lot.Pool') as PoolMock: PoolMock.return_value.get.return_value = ShipmentIn - state = wizard.transition_create_shipment() + with patch.object( + wizard, 'transition_shipping', return_value='end' + ) as transition_shipping: + state = wizard.transition_create_shipment() - self.assertEqual(state, 'ship') + self.assertEqual(state, 'end') ShipmentIn.create.assert_called_once_with([{ 'supplier': 30, 'from_location': 10, 'to_location': 20, }]) - self.assertEqual(wizard.default_ship(None)['shipment_in'], 40) + self.assertEqual(wizard.ship.shipment_in, created_shipment) + transition_shipping.assert_called_once_with() @with_transaction() def test_get_mtm_applies_component_ratio_as_percentage(self):