From 89f9649d6b5bcdf544484f77914fc565a5787fcc Mon Sep 17 00:00:00 2001 From: Donatas Date: Tue, 4 May 2021 09:44:19 +0000 Subject: [PATCH] [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 --- addons/purchase_stock/models/purchase.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/addons/purchase_stock/models/purchase.py b/addons/purchase_stock/models/purchase.py index 8f4c1d74eb2..e82e74eed01 100644 --- a/addons/purchase_stock/models/purchase.py +++ b/addons/purchase_stock/models/purchase.py @@ -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 # --------------------------------------------------