From c82ec7a6fde6c4b922016250338b759d38a42728 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 22 Jun 2017 16:48:26 +0200 Subject: [PATCH] [FIX] purchase: cancelled procurement If two MOs are using the same PO, when we cancel the first MO, the check availability of second MO is not working. The incoming shipment of the Purchase Order has the first MO's move_id as the destination move. When we cancel the first MO, the incoming shipment of Purchase Order still holds the first MO's move. Because of that reason, the check availability is not working for the second MO. While setting the destination move for the stock moves of the incoming shipment, it should ignore the cancelled procurements. Closes #17701 opw-748074 Courtesy of @suganthikarunanithi --- addons/purchase/models/purchase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index e65622d0eb4..be116a45504 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -673,7 +673,7 @@ class PurchaseOrderLine(models.Model): } # Fullfill all related procurements with this po line diff_quantity = self.product_qty - qty - for procurement in self.procurement_ids: + for procurement in self.procurement_ids.filtered(lambda p: p.state != 'cancel'): # If the procurement has some moves already, we should deduct their quantity sum_existing_moves = sum(x.product_qty for x in procurement.move_ids if x.state != 'cancel') existing_proc_qty = procurement.product_id.uom_id._compute_quantity(sum_existing_moves, procurement.product_uom)