From 1d1debf6ae521d766bec10792d50b4835c0f479f Mon Sep 17 00:00:00 2001
From: Denis Ledoux <dle@odoo.com>
Date: Mon, 6 Jun 2016 17:52:22 +0200
Subject: [PATCH] [FIX] purchase: exclude cancelled invoice for billed qty

The billed quantity field on the purchase order line
must exclude the cancelled invoice, as a cancelled invoice
is not considered as invoiced.

`draft` could be considered as well, but we do not
take the chance now, as this field is used
when creating a new invoice, to determine the
quantity to invoice. Therefore, if there are
draft invoices with some quantities invoiced,
it can make sense to reduce the quantity
in this new invoice. Nevertheless, it must not be the case
for cancelled invoices.

opw-679363
---
 addons/purchase/purchase.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py
index b969c9beb210..7825b687ba65 100644
--- a/addons/purchase/purchase.py
+++ b/addons/purchase/purchase.py
@@ -455,7 +455,8 @@ class PurchaseOrderLine(models.Model):
         for line in self:
             qty = 0.0
             for inv_line in line.invoice_lines:
-                qty += inv_line.uom_id._compute_qty_obj(inv_line.uom_id, inv_line.quantity, line.product_uom)
+                if inv_line.invoice_id.state not in ['cancel']:
+                    qty += inv_line.uom_id._compute_qty_obj(inv_line.uom_id, inv_line.quantity, line.product_uom)
             line.qty_invoiced = qty
 
     @api.depends('order_id.state', 'move_ids.state')
-- 
GitLab