[FIX] repair: cancel non picked moves

Confirming a repair order with parts assign moves quantities.
Ending it without any of the picked flags automatically pick them.
But ending it with some non-picked parts does not cancel the moves.
Now they are.

closes odoo/odoo#149157

Task: 3679247
Signed-off-by: Steve Van Essche <svs@odoo.com>
This commit is contained in:
JF Aubert
2024-02-02 23:00:28 +00:00
parent b2406f72ad
commit 54ada01a07
2 changed files with 16 additions and 4 deletions
+9 -2
View File
@@ -436,7 +436,7 @@ class Repair(models.Model):
if move_id:
repair.move_id = move_id
all_moves = self.move_ids + product_moves
all_moves._action_done()
all_moves._action_done(cancel_backorder=True)
for sale_line in self.move_ids.sale_line_id:
price_unit = sale_line.price_unit
@@ -451,7 +451,14 @@ class Repair(models.Model):
"""
if self.filtered(lambda repair: repair.state != 'under_repair'):
raise UserError(_("Repair must be under repair in order to end reparation."))
if any(float_compare(move.quantity, move.product_uom_qty, precision_rounding=move.product_uom.rounding) < 0 for move in self.move_ids):
partial_moves = set()
picked_moves = set()
for move in self.move_ids:
if float_compare(move.quantity, move.product_uom_qty, precision_rounding=move.product_uom.rounding) < 0:
partial_moves.add(move.id)
if move.picked:
picked_moves.add(move.id)
if partial_moves or picked_moves and len(picked_moves) < len(self.move_ids):
ctx = dict(self.env.context or {})
ctx['default_repair_ids'] = self.ids
return {
+7 -2
View File
@@ -303,8 +303,13 @@ class TestRepair(common.TransactionCase):
self.assertEqual(lineD.state, 'assigned')
num_of_lines = len(repair.move_ids)
self.assertFalse(repair.move_id)
repair.action_repair_end()
end_action = repair.action_repair_end()
self.assertEqual(end_action.get("res_model"), "repair.warn.uncomplete.move")
warn_uncomplete_wizard = Form(
self.env['repair.warn.uncomplete.move']
.with_context(**end_action['context'])
).save()
warn_uncomplete_wizard.action_validate()
self.assertEqual(repair.state, "done")
done_moves = repair.move_ids - lineD
#line a,b,c are 'done', line d is 'cancel'