From 30d8c17ffdffd79585444422c5469b317c105ef8 Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Thu, 14 Oct 2021 11:28:39 +0000 Subject: [PATCH] [IMP] stock: recompute state speedup The recomputation of stock move state is often done with already the correct state (for instance in the case of move line deletion only one of the deletion will change the state). This commit check the move state before changing it only when it's necessary. Task: 2507143 X-original-commit: 80033446a091ff3ba98c58ba44ad665bfba30c98 Part-of: odoo/odoo#78547 Co-authored-by: Remy Voet --- addons/mrp/models/mrp_production.py | 5 +++-- addons/stock/models/stock_move.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 9f7c6d4dfd7..ddcb4853653 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1178,7 +1178,9 @@ class MrpProduction(models.Model): self.move_raw_ids._trigger_scheduler() self.picking_ids.filtered( lambda p: p.state not in ['cancel', 'done']).action_confirm() - self.state = 'confirmed' + # Force confirm state only for draft production not for more advanced state like + # 'progress' (in case of backorders with some qty_producing) + self.filtered(lambda mo: mo.state == 'draft').state = 'confirmed' return True def action_assign(self): @@ -1518,7 +1520,6 @@ class MrpProduction(models.Model): # Remove the serial move line without reserved quantity. Post inventory will assigned all the non done moves # So those move lines are duplicated. backorders.move_raw_ids.move_line_ids.filtered(lambda ml: ml.product_id.tracking == 'serial' and ml.product_qty == 0).unlink() - backorders.move_raw_ids._recompute_state() for old_wo, wo in zip(self.workorder_ids, backorders.workorder_ids): wo.qty_produced = max(old_wo.qty_produced - old_wo.qty_producing, 0) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 1bb5fe23c1c..c928c7af007 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1747,7 +1747,7 @@ class StockMove(models.Model): else: moves_state_to_write['confirmed'].add(move.id) for state, moves_ids in moves_state_to_write.items(): - self.browse(moves_ids).write({'state': state}) + self.browse(moves_ids).filtered(lambda m: m.state != state).state = state @api.model def _consuming_picking_types(self):