From 8aeae17d78578819fa1eb6f85b8e6c092baeb4f4 Mon Sep 17 00:00:00 2001 From: qdp-odoo Date: Thu, 26 Nov 2015 16:42:14 +0100 Subject: [PATCH] [REF] sale, sale_stock: added some comments to clear some aspects of the code related to the last changes on SO (salepocalypse) --- addons/sale/sale.py | 4 +++- addons/sale_stock/sale_stock.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 559f2ebfa79..3ae2f928a44 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -486,7 +486,9 @@ class SaleOrderLine(models.Model): def _get_invoice_qty(self): """ Compute the quantity invoiced. If case of a refund, the quantity invoiced is decreased. Note - that this is the case only if the refund is generated from the SO. + that this is the case only if the refund is generated from the SO and that is intentional: if + a refund made would automatically decrease the invoiced quantity, then there is a risk of reinvoicing + it automatically, which may not be wanted at all. That's why the refund has to be created from the SO """ for line in self: qty_invoiced = 0.0 diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index 72bf6b0843d..4f417d31e05 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -159,10 +159,14 @@ class SaleOrderLine(models.Model): @api.multi def _get_delivered_qty(self): + """Computes the delivered quantity on sale order lines, based on done stock moves related to its procurements + """ self.ensure_one() super(SaleOrderLine, self)._get_delivered_qty() qty = 0.0 for move in self.procurement_ids.mapped('move_ids').filtered(lambda r: r.state == 'done' and not r.scrapped): + #Note that we don't decrease quantity for customer returns on purpose: these are exeptions that must be treated manually. Indeed, + #modifying automatically the delivered quantity may trigger an automatic reinvoicing (refund) of the SO, which is definitively not wanted if move.location_dest_id.usage == "customer": qty += self.env['product.uom']._compute_qty_obj(move.product_uom, move.product_uom_qty, self.product_uom) return qty