From 8550300972c9bf69668c409ce0899d67825eb5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 10 Mar 2026 14:54:48 +0100 Subject: [PATCH] Set the default locations for stock move when production is set Closes #14665 --- modules/production/stock.py | 30 +++++++++++++++---- .../tests/scenario_production_lot_number.rst | 2 -- .../tests/scenario_production_lot_trace.rst | 4 --- .../tests/scenario_production_set_cost.rst | 2 -- .../tests/scenario_production_waste.rst | 5 ---- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/modules/production/stock.py b/modules/production/stock.py index 9ef1025a28..ca6a92b204 100644 --- a/modules/production/stock.py +++ b/modules/production/stock.py @@ -71,7 +71,8 @@ class Move(metaclass=PoolMeta): 'production', "Production", states={ 'invisible': ~Eval('production'), - }), + }, + depends=['production_input', 'production_output']), 'on_change_with_production', searcher='search_production') production_cost_price_updated = fields.Boolean( "Cost Price Updated", readonly=True, @@ -92,10 +93,29 @@ class Move(metaclass=PoolMeta): cls._allow_modify_closed_period.add('production_cost_price_updated') @fields.depends( - 'production_output', '_parent_production_output.company', - 'to_location') + 'production_input', + '_parent_production_input.warehouse', + '_parent_production_input.location', + 'from_location', 'to_location') + def on_change_production_input(self): + if self.production_input: + if not self.from_location: + self.from_location = self.production_input.picking_location + if not self.to_location: + self.to_location = self.production_input.location + + @fields.depends( + 'production_output', + '_parent_production_output.company', + '_parent_production_output.warehouse', + '_parent_production_output.location', + 'from_location', 'to_location') def on_change_production_output(self): if self.production_output: + if not self.from_location: + self.from_location = self.production_output.location + if not self.to_location: + self.to_location = self.production_output.output_location if self.production_output.company: self.currency = self.production_output.company.currency if self.to_location and self.to_location.type == 'lost_found': @@ -117,9 +137,9 @@ class Move(metaclass=PoolMeta): 'production_input', '_parent_production_input.id', 'production_output', '_parent_production_output.id') def on_change_with_production(self, name=None): - if self.production_input: + if self.production_input and self.production_input.id >= 0: return self.production_input - elif self.production_output: + elif self.production_output and self.production_output.id >= 0: return self.production_output @classmethod diff --git a/modules/production/tests/scenario_production_lot_number.rst b/modules/production/tests/scenario_production_lot_number.rst index e4a036886b..e1c10fbb27 100644 --- a/modules/production/tests/scenario_production_lot_number.rst +++ b/modules/production/tests/scenario_production_lot_number.rst @@ -46,8 +46,6 @@ Make a production:: >>> production = Production() >>> output = production.outputs.new() - >>> output.from_location = production.location - >>> output.to_location = production.warehouse.storage_location >>> output.product = product >>> output.quantity = 1 >>> output.unit_price = Decimal(0) diff --git a/modules/production/tests/scenario_production_lot_trace.rst b/modules/production/tests/scenario_production_lot_trace.rst index ffdc283b36..772ec91926 100644 --- a/modules/production/tests/scenario_production_lot_trace.rst +++ b/modules/production/tests/scenario_production_lot_trace.rst @@ -51,14 +51,10 @@ Make a production:: >>> production = Production() >>> input = production.inputs.new() - >>> input.from_location = production.warehouse.storage_location - >>> input.to_location = production.location >>> input.product = component >>> input.lot = component_lot >>> input.quantity = 1 >>> output = production.outputs.new() - >>> output.from_location = production.location - >>> output.to_location = production.warehouse.storage_location >>> output.product = product >>> output.lot = product_lot >>> output.quantity = 1 diff --git a/modules/production/tests/scenario_production_set_cost.rst b/modules/production/tests/scenario_production_set_cost.rst index 75de7fc8e7..f29d62c8f9 100644 --- a/modules/production/tests/scenario_production_set_cost.rst +++ b/modules/production/tests/scenario_production_set_cost.rst @@ -68,8 +68,6 @@ Make a production with 2 unused component:: >>> output.quantity = 2 >>> output.unit_price = Decimal(0) >>> output.currency = get_currency() - >>> output.from_location = production.location - >>> output.to_location = production.warehouse.storage_location >>> production.click('do') Check output price:: diff --git a/modules/production/tests/scenario_production_waste.rst b/modules/production/tests/scenario_production_waste.rst index 60fdcced62..304c1f824d 100644 --- a/modules/production/tests/scenario_production_waste.rst +++ b/modules/production/tests/scenario_production_waste.rst @@ -56,8 +56,6 @@ Run the production:: >>> input = production.inputs.new() >>> input.quantity = 20.0 >>> input.product = component - >>> input.from_location = warehouse_loc.storage_location - >>> input.to_location = production.location >>> production.click('wait') >>> production.click('assign_force') >>> production.click('run') @@ -67,14 +65,11 @@ Create outputs including waste products:: >>> output = production.outputs.new() >>> output.quantity = 1.0 >>> output.product = product - >>> output.from_location = production.location - >>> output.to_location = warehouse_loc.storage_location >>> output.unit_price = Decimal('0') >>> output.currency = production.company.currency >>> waste_output = production.outputs.new() >>> waste_output.quantity = 1.0 >>> waste_output.product = product - >>> waste_output.from_location = production.location >>> waste_output.to_location = lost_found_loc >>> production.click('do') >>> production.cost