From e2f54d904cfff3548141dd511c34cbbfd03b8410 Mon Sep 17 00:00:00 2001 From: yhu-odoo Date: Fri, 3 Nov 2023 15:57:32 +0100 Subject: [PATCH] [FIX] mrp: wrong manual consumption value in onchange When `manual_consumption` field on sm is used in any onchange function, the value will always be computed for the `new_id` record instead of using the original value stored in database. This results in a different value in some cases. In this commit, we chech if the compute function is called from an onchange funtion or not, if so, we use the original value instead of recomputation. closes odoo/odoo#140753 Signed-off-by: William Henrotin (whe) --- addons/mrp/models/mrp_production.py | 5 +++-- addons/mrp/models/stock_move.py | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index a94288c40df..d3288b68ceb 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1200,12 +1200,13 @@ class MrpProduction(models.Model): if move.manual_consumption and move.picked: continue - if move._should_bypass_set_qty_producing(): + # sudo needed for portal users + if move.sudo()._should_bypass_set_qty_producing(): continue new_qty = float_round((self.qty_producing - self.qty_produced) * move.unit_factor, precision_rounding=move.product_uom.rounding) move._set_quantity_done(new_qty) - if (not move.manual_consumption and not move._origin.manual_consumption): + if not move.manual_consumption: move.picked = True def _update_raw_moves(self, factor): diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 036d26dce33..ff5777651b1 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -138,9 +138,11 @@ class StockMove(models.Model): @api.depends('state', 'product_id', 'operation_id') def _compute_manual_consumption(self): for move in self: - if move.state != 'draft': - continue - move.manual_consumption = move._is_manual_consumption() + # when computed for new_id in onchange, use value from _origin + if move != move._origin: + move.manual_consumption = move._origin.manual_consumption + elif move.state == 'draft': + move.manual_consumption = move._is_manual_consumption() @api.depends('bom_line_id') def _compute_description_bom_line(self):