[FIX] purchase_stock: PO line related stock moves getting stuck

When purchase order line is removed, related stock moves procure method stays as "Advanced" which doesn't allow reservation from stock

closes odoo/odoo#70708

X-original-commit: 17d0d1bc6294578e035e29a550a7e90ae7ef2f5f
Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
This commit is contained in:
Donatas
2021-05-11 16:59:39 +00:00
committed by William Henrotin
parent 16a0427bc4
commit 89f9649d6b
+12
View File
@@ -362,6 +362,18 @@ class PurchaseOrderLine(models.Model):
action['context']['warehouse'] = warehouse.id
return action
def unlink(self):
self.move_ids._action_cancel()
ppg_cancel_lines = self.filtered(lambda line: line.propagate_cancel)
ppg_cancel_lines.move_dest_ids._action_cancel()
not_ppg_cancel_lines = self.filtered(lambda line: not line.propagate_cancel)
not_ppg_cancel_lines.move_dest_ids.write({'procure_method': 'make_to_stock'})
not_ppg_cancel_lines.move_dest_ids.recompute_state()
return super().unlink()
# --------------------------------------------------
# Business methods
# --------------------------------------------------