[FIX] mrp: fix singleton error while multiple moves in 'move_finished_ids'

ValueError: Expected singleton: stock.move(32, 33)

This error occurs when we get the multiple lines of the same products in
'finish_moves' and after that when we try to mark as done at that time this
error occurs.

applying these changes will resolve this issue.

sentry-4217897073

closes odoo/odoo#124251

X-original-commit: 4933609bd6a8473272f6bb94a1de8aea5cdf6687
Signed-off-by: Tiffany Chang <tic@odoo.com>
This commit is contained in:
Om Rabara
2023-06-08 16:10:16 +02:00
parent 976491e012
commit 491d22e1df
+6 -4
View File
@@ -1508,10 +1508,12 @@ class MrpProduction(models.Model):
for order in self:
finish_moves = order.move_finished_ids.filtered(lambda m: m.product_id == order.product_id and m.state not in ('done', 'cancel'))
# the finish move can already be completed by the workorder.
if finish_moves and not finish_moves.quantity_done:
finish_moves._set_quantity_done(float_round(order.qty_producing - order.qty_produced, precision_rounding=order.product_uom_id.rounding, rounding_method='HALF-UP'))
if finish_moves.has_tracking != 'none' and order.lot_producing_id:
finish_moves.move_line_ids.lot_id = order.lot_producing_id
for move in finish_moves:
if move.quantity_done:
continue
move._set_quantity_done(float_round(order.qty_producing - order.qty_produced, precision_rounding=order.product_uom_id.rounding, rounding_method='HALF-UP'))
if move.has_tracking != 'none' and order.lot_producing_id:
move.move_line_ids.lot_id = order.lot_producing_id
# workorder duration need to be set to calculate the price of the product
for workorder in order.workorder_ids:
if workorder.state not in ('done', 'cancel'):