[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) <arm@odoo.com>
This commit is contained in:
Arnold Moyaux
2024-04-22 13:39:46 +00:00
parent 26092e6972
commit 13708008ed
+9 -2
View File
@@ -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):