Link to transport

This commit is contained in:
2026-06-07 07:41:33 +02:00
parent 1339f9b2f1
commit 126225ea6a
2 changed files with 13 additions and 11 deletions

View File

@@ -2958,7 +2958,7 @@ class LotShipping(Wizard):
'lot.shipping.start', 'lot.shipping.start',
'purchase_trade.shipping_view_form', [ 'purchase_trade.shipping_view_form', [
Button("Cancel", 'end', 'tryton-cancel'), 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), Button("Link", 'shipping', 'tryton-ok', default=True),
]) ])
@@ -2972,8 +2972,6 @@ class LotShipping(Wizard):
def default_ship(self, fields): def default_ship(self, fields):
values = {} values = {}
if getattr(self, '_created_shipment_in', None):
values['shipment_in'] = self._created_shipment_in
if len(self.records) != 1: if len(self.records) != 1:
return values return values
record = self.records[0] record = self.records[0]
@@ -3017,10 +3015,10 @@ class LotShipping(Wizard):
def transition_create_shipment(self): def transition_create_shipment(self):
ShipmentIn = Pool().get('stock.shipment.in') ShipmentIn = Pool().get('stock.shipment.in')
if self.ship.shipment_in: if self.ship.shipment_in:
return 'ship' return self.transition_shipping()
shipment, = ShipmentIn.create([self._shipment_in_create_values()]) shipment, = ShipmentIn.create([self._shipment_in_create_values()])
self._created_shipment_in = shipment.id self.ship.shipment_in = shipment
return 'ship' return self.transition_shipping()
def transition_shipping(self): def transition_shipping(self):
Lot = Pool().get('lot.lot') Lot = Pool().get('lot.lot')

View File

@@ -219,8 +219,8 @@ class PurchaseTradeTestCase(ModuleTestCase):
'planned_to_location': 20, 'planned_to_location': 20,
}) })
def test_lot_shipping_create_shipment_uses_planned_locations(self): def test_lot_shipping_create_shipment_links_planned_locations(self):
'link to transport creates shipment in from planned locations' 'link to transport creates shipment in and links planned locations'
wizard = lot_module.LotShipping() wizard = lot_module.LotShipping()
supplier = Mock(id=30) supplier = Mock(id=30)
created_shipment = Mock(id=40) created_shipment = Mock(id=40)
@@ -236,15 +236,19 @@ class PurchaseTradeTestCase(ModuleTestCase):
with patch('trytond.modules.purchase_trade.lot.Pool') as PoolMock: with patch('trytond.modules.purchase_trade.lot.Pool') as PoolMock:
PoolMock.return_value.get.return_value = ShipmentIn 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([{ ShipmentIn.create.assert_called_once_with([{
'supplier': 30, 'supplier': 30,
'from_location': 10, 'from_location': 10,
'to_location': 20, '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() @with_transaction()
def test_get_mtm_applies_component_ratio_as_percentage(self): def test_get_mtm_applies_component_ratio_as_percentage(self):