From c6a7e4fbb9c01517f0cd34ccd18a1a193b59d7d5 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 22 Mar 2017 10:43:04 +0100 Subject: [PATCH] [FIX] purchase: billed qty In a SO, the "Invoiced Qty" can decrease if the refund is generated from the SO. It doesn't decrease if the refund is generated from the Invoice. However, we don't have this mechanism in a PO since the invoice is not generated directly from the PO. There is therefore no way to decrease the "Billed Qty". We authorize the "Billed Qty" to decrease in the case of PO. Complement of commit 9b5281adb41c1c388cba2ec942d14040a5b65f16 opw-724474 --- addons/purchase/models/purchase.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 158a8492f1d..26a502c7673 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -525,8 +525,11 @@ class PurchaseOrderLine(models.Model): for line in self: qty = 0.0 for inv_line in line.invoice_lines: - if inv_line.invoice_id.state not in ['cancel'] and inv_line.invoice_id.type == 'in_invoice': - qty += inv_line.uom_id._compute_quantity(inv_line.quantity, line.product_uom) + if inv_line.invoice_id.state not in ['cancel']: + if inv_line.invoice_id.type == 'in_invoice': + qty += inv_line.uom_id._compute_quantity(inv_line.quantity, line.product_uom) + elif inv_line.invoice_id.type == 'in_refund': + qty -= inv_line.uom_id._compute_quantity(inv_line.quantity, line.product_uom) line.qty_invoiced = qty @api.depends('order_id.state', 'move_ids.state')