From e1ff6ce3d927caf29f7f673f9b4bc404ec4bce59 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Mon, 13 Aug 2018 11:20:13 +0200 Subject: [PATCH] [FIX] purchase: cancel a PO undo the closest picking cancellation Usecase to reproduce: - Set a product buy and MTO - Create a SO with it and cancel it - All the pickings are cancel - Cancel the PO - The picking that generate the PO is set to confirm The picking should remain in cancel state It happens because the button_cancel method still consider the canceled moves. This commit only modify destination moves if they still require an action from the user. --- addons/purchase/models/purchase.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 0a54ecc6c57..42f946f1d2b 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -370,10 +370,11 @@ class PurchaseOrder(models.Model): if order.state in ('draft', 'sent', 'to approve'): for order_line in order.order_line: if order_line.move_dest_ids: - siblings_states = (order_line.move_dest_ids.mapped('move_orig_ids')).mapped('state') + move_dest_ids = order_line.move_dest_ids.filtered(lambda m: m.state not in ('done', 'cancel')) + siblings_states = (move_dest_ids.mapped('move_orig_ids')).mapped('state') if all(state in ('done', 'cancel') for state in siblings_states): - order_line.move_dest_ids.write({'procure_method': 'make_to_stock'}) - order_line.move_dest_ids._recompute_state() + move_dest_ids.write({'procure_method': 'make_to_stock'}) + move_dest_ids._recompute_state() for pick in order.picking_ids.filtered(lambda r: r.state != 'cancel'): pick.action_cancel()