From d5064e1b0b4eadbb883bdccba284df1cae670219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 16 Jul 2026 11:04:37 +0200 Subject: [PATCH] Make locations readonly on stock move when linked to a shipment without being edited from it This ensures that the domain from the shipment fields can not be skipped. Closes #12564 --- modules/stock/move.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/stock/move.py b/modules/stock/move.py index b9cd788970..5b9157d52e 100644 --- a/modules/stock/move.py +++ b/modules/stock/move.py @@ -18,7 +18,7 @@ from trytond.model import ( from trytond.model.exceptions import AccessError from trytond.modules.product import price_digits, round_price from trytond.pool import Pool -from trytond.pyson import Bool, Eval, Id, If, TimeDelta +from trytond.pyson import Bool, Equal, Eval, Id, If, TimeDelta from trytond.tools import cached_property from trytond.transaction import Transaction, without_check_access @@ -237,7 +237,13 @@ class Move(Workflow, ModelSQL, ModelView): ]) from_location = fields.Many2One( 'stock.location', "From Location", - required=True, states=STATES, + required=True, + states={ + 'readonly': ( + STATES['readonly'] + | (Eval('shipment') + & Equal(Eval('_parent_shipment.id', None), None))), + }, domain=[ LOCATION_DOMAIN, ('id', '!=', Eval('to_location', -1)), @@ -256,7 +262,13 @@ class Move(Workflow, ModelSQL, ModelView): 'on_change_with_from_location_name') to_location = fields.Many2One( 'stock.location', "To Location", - required=True, states=STATES, + required=True, + states={ + 'readonly': ( + STATES['readonly'] + | (Eval('shipment') + & Equal(Eval('_parent_shipment.id', None), None))), + }, domain=[ LOCATION_DOMAIN, ('id', '!=', Eval('from_location', -1)),