[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.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user