From a3e197507410d2bf28bca86eaf786b99d5b8a2fb Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Thu, 17 Nov 2022 15:25:16 +0000 Subject: [PATCH] [FIX] mrp: prevent editing of readonly locations for MO moves Issue: In the MO view, the src location for components was editable and the dest location for byproducts was editable when neither of these should be. Due to the same field appearing twice in the same x2many field list, there were 2 issues: 1. something changed (probably during OWL refactoring) that made it so the 2nd invisible field instance of the field was overriding the "readonly='1'" property of the 1st instance when it was in the view (i.e. when multi-locations is active) [in previous versions this did not happen] 2. because of the change by https://github.com/odoo/odoo/commit/168cbe66bee7824bdf389de5c6c680342e27bc6d we ensure that these two required fields are always correctly set (to the MO's values as per the default when multi-loc is active) when the MO's moves are created. Part of general bugfix task: 2985735 closes odoo/odoo#106542 X-original-commit: 1bb2c44d32e669a9b936da90cbd80721b2c897ef Related: odoo/enterprise#34396 Signed-off-by: William Henrotin (whe) Signed-off-by: Tiffany Chang --- addons/mrp/models/stock_move.py | 4 ++++ addons/mrp/views/mrp_production_views.xml | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 8d504339336..c2515e913e5 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -285,11 +285,15 @@ class StockMove(models.Model): product_id_to_product[values['product_id']] = product values['location_dest_id'] = mo.production_location_id.id values['price_unit'] = product.standard_price + if not values.get('location_id'): + values['location_id'] = mo.location_src_id.id continue # produced products + byproducts values['location_id'] = mo.production_location_id.id values['date'] = mo._get_date_planned_finished() values['date_deadline'] = mo.date_deadline + if not values.get('location_dest_id'): + values['location_dest_id'] = mo.location_dest_id.id return super().create(vals_list) def write(self, vals): diff --git a/addons/mrp/views/mrp_production_views.xml b/addons/mrp/views/mrp_production_views.xml index 0694d4ac7ef..7886f7e3dea 100644 --- a/addons/mrp/views/mrp_production_views.xml +++ b/addons/mrp/views/mrp_production_views.xml @@ -304,7 +304,7 @@ attrs="{'readonly': ['|', ('state', '=', 'cancel'), '&', ('state', '=', 'done'), ('is_locked', '=', True)]}" options="{'delete': [('state', '=', 'draft')]}"> - + @@ -323,7 +323,6 @@ - @@ -373,7 +372,7 @@ - + @@ -392,7 +391,6 @@ -