From 13708008ed2c14bdebfec2a20c8ce7fccf7bc912 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Wed, 21 Feb 2024 15:27:05 +0000 Subject: [PATCH] [FIX] stock: remove mto link when product is stolen A lot of users don't understand why they can't reserve in MTO chain after moving a product with an immediate transfer. It's due to the double check of _action_assign that look where the move orig stored the product and if the quants exist in this exact location. In our case the product was moved so the match doesn't work. We introduce an new parameter to check if modifying the behavior on those cases could work. When _free_reservation is call on a `stock.move.line`, we expect to never find it at this place anymore (except if we bring it back). Then we drop the MTO link for this step and use the MTS reservation. WARNING, this parameter could remove too many mto links. e.g. There is multiple stock.move.line linked to different locations they will lose the link for product remaining in the same place. closes odoo/odoo#155118 X-original-commit: af41b538d89a3c59c78f65c9174c7fbf4aa43922 Signed-off-by: Arnold Moyaux (arm) --- addons/stock/models/stock_move_line.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index bb6d19d6d46..3ae1657f487 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -3,7 +3,7 @@ from collections import Counter, defaultdict -from odoo import _, api, fields, tools, models +from odoo import _, api, fields, tools, models, Command from odoo.exceptions import UserError, ValidationError from odoo.tools import OrderedSet, groupby from odoo.tools.float_utils import float_compare, float_is_zero, float_round @@ -742,7 +742,14 @@ class StockMoveLine(models.Model): candidate.quantity -= candidate.product_id.uom_id._compute_quantity(quantity, candidate.product_uom_id, rounding_method='HALF-UP') break - self.env['stock.move.line'].browse(to_unlink_candidate_ids).unlink() + move_line_to_unlink = self.env['stock.move.line'].browse(to_unlink_candidate_ids) + if self.env['ir.config_parameter'].sudo().get_param('stock.break_mto'): + for m in (move_line_to_unlink.move_id | move_to_reassign): + m.write({ + 'procure_method': 'make_to_stock', + 'move_orig_ids': [Command.clear()] + }) + move_line_to_unlink.unlink() move_to_reassign._action_assign() def _get_aggregated_properties(self, move_line=False, move=False):