summaryrefslogtreecommitdiff
path: root/addons/product_margin
diff options
context:
space:
mode:
authorAnh Thao Pham (pta) <pta@odoo.com>2021-02-03 14:23:37 +0000
committerAnh Thao Pham (pta) <pta@odoo.com>2021-02-05 10:13:30 +0000
commit8c7feb45f1ee8581e259f3c2aaff7a139f516d94 (patch)
tree0de8b093284652b08e70bb0c93112961b56eb7d0 /addons/product_margin
parent1e3a11cb5f7a1f07a9e61240f027ff54c0dee847 (diff)
[FIX] product_margin: fix Avg. Sale Unit Price
- Install product_margin - Go to Invoicing > Customers > Invoices and create an Invoice - Add a Credit Note - Go to Accounting > Reporting > Product Margins and check Product used in the Invoice The "Avg. Sale Unit Price" is incorrect. It should be 0 as it is for "# Invoiced in Sale" Credit Notes are not taken into consideration when computing "Avg. Sale Unit Price". This is also the case for discount. opw-2382797 closes odoo/odoo#65583 X-original-commit: a3ee7adff2b0662ae8875e1eab13228c165f5428 Signed-off-by: Anh Thao PHAM <kitan191@users.noreply.github.com>
Diffstat (limited to 'addons/product_margin')
-rw-r--r--addons/product_margin/models/product_product.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/addons/product_margin/models/product_product.py b/addons/product_margin/models/product_product.py
index d5c5c6c151b..97562fce0c5 100644
--- a/addons/product_margin/models/product_product.py
+++ b/addons/product_margin/models/product_product.py
@@ -109,7 +109,10 @@ class ProductProduct(models.Model):
sqlstr = """
WITH currency_rate AS ({})
SELECT
- SUM(l.price_unit / (CASE COALESCE(cr.rate, 0) WHEN 0 THEN 1.0 ELSE cr.rate END) * l.quantity) / NULLIF(SUM(l.quantity),0) AS avg_unit_price,
+ SUM(
+ l.price_unit / (CASE COALESCE(cr.rate, 0) WHEN 0 THEN 1.0 ELSE cr.rate END) *
+ l.quantity * (CASE WHEN i.move_type IN ('out_invoice', 'in_invoice') THEN 1 ELSE -1 END) * ((100 - l.discount) * 0.01)
+ ) / NULLIF(SUM(l.quantity * (CASE WHEN i.move_type IN ('out_invoice', 'in_invoice') THEN 1 ELSE -1 END)), 0) AS avg_unit_price,
SUM(l.quantity * (CASE WHEN i.move_type IN ('out_invoice', 'in_invoice') THEN 1 ELSE -1 END)) AS num_qty,
SUM(ABS(l.balance) * (CASE WHEN i.move_type IN ('out_invoice', 'in_invoice') THEN 1 ELSE -1 END)) AS total,
SUM(l.quantity * pt.list_price * (CASE WHEN i.move_type IN ('out_invoice', 'in_invoice') THEN 1 ELSE -1 END)) AS sale_expected