From 9a810565b0ca1bb8572c1742009d16277cdcccd4 Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Fri, 15 Jun 2018 15:54:20 +0200 Subject: [PATCH] [FIX] purchase: Canceling the receipt of a receipt Canceling the delivery order created for a "Make to order" product cancels the related procurement. But canceling the receipt order created for a "Buy" product" with reordering rule didn't cancel the related procurement. In some cases, it can block the application of the reordering rules. Now the related procurement is canceled when the receipt order is canceled. opw:1845345 --- addons/purchase/models/purchase.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 2ddbaf8a897..da83740a31f 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -917,10 +917,23 @@ class ProcurementOrder(models.Model): @api.multi def _check(self): - if self.purchase_line_id: + if self.rule_id.action == 'buy': + # In case Phantom BoM splits only into procurements if not self.move_ids: + if self.purchase_line_id and self.purchase_line_id.order_id.state not in ('purchase', 'done', 'cancel'): + return False + else: + return True + move_all_done_or_cancel = all(move.state in ['done', 'cancel'] for move in self.move_ids) + move_all_cancel = all(move.state == 'cancel' for move in self.move_ids) + if not move_all_done_or_cancel: + return False + elif move_all_done_or_cancel and not move_all_cancel: + return True + else: + self.message_post(body=_('All stock moves have been cancelled for this procurement.')) + self.write({'state': 'cancel'}) return False - return all(move.state in ('done', 'cancel') for move in self.move_ids) and any(move.state == 'done' for move in self.move_ids) return super(ProcurementOrder, self)._check() def _get_purchase_schedule_date(self):