[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 <ryv@odoo.com>
This commit is contained in:
William Henrotin
2021-10-18 12:45:56 +00:00
co-authored by Remy Voet
parent 425ff940da
commit 30d8c17ffd
2 changed files with 4 additions and 3 deletions
+3 -2
View File
@@ -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)
+1 -1
View File
@@ -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):