summaryrefslogtreecommitdiff
path: root/addons/product_margin
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2019-07-23 09:55:56 +0200
committerMartin Trigaux <mat@odoo.com>2019-07-23 13:41:00 +0200
commite266c7c98a6a4b89c13eb7eb38709cc0251ea47f (patch)
tree1b27ca28cac9f1d8577ae2bf14d0682e8920f05f /addons/product_margin
parent5c705c51cd8377b1c6e1bb2513db34afe48189ee (diff)
parent5e4c1b370123dee4e6d6a91cd9582ba41c4d8bd4 (diff)
[MERGE] Forward port of 12.0 to saas-12.2 up to 5e4c1b370123dee
Diffstat (limited to 'addons/product_margin')
-rw-r--r--addons/product_margin/i18n/km.po2
-rw-r--r--addons/product_margin/models/product_product.py10
2 files changed, 9 insertions, 3 deletions
diff --git a/addons/product_margin/i18n/km.po b/addons/product_margin/i18n/km.po
index 68a1325f98a..45e24150f1c 100644
--- a/addons/product_margin/i18n/km.po
+++ b/addons/product_margin/i18n/km.po
@@ -237,7 +237,7 @@ msgstr ""
#. module: product_margin
#: model_terms:ir.ui.view,arch_db:product_margin.view_product_margin_form
msgid "Purchases"
-msgstr ""
+msgstr "ការទិញ"
#. module: product_margin
#: model_terms:ir.ui.view,arch_db:product_margin.view_product_margin_form
diff --git a/addons/product_margin/models/product_product.py b/addons/product_margin/models/product_product.py
index 9fc94ea6310..2e7b20f6e96 100644
--- a/addons/product_margin/models/product_product.py
+++ b/addons/product_margin/models/product_product.py
@@ -104,8 +104,9 @@ class ProductProduct(models.Model):
#Cost price is calculated afterwards as it is a property
sqlstr = """
+ WITH currency_rate AS ({})
select
- sum(l.price_unit * 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)/nullif(sum(l.quantity),0) as avg_unit_price,
sum(l.quantity) as num_qty,
sum(l.quantity * (l.price_subtotal_signed/(nullif(l.quantity,0)))) as total,
sum(l.quantity * pt.list_price) as sale_expected
@@ -113,8 +114,13 @@ class ProductProduct(models.Model):
left join account_invoice i on (l.invoice_id = i.id)
left join product_product product on (product.id=l.product_id)
left join product_template pt on (pt.id = product.product_tmpl_id)
+ left join currency_rate cr on
+ (cr.currency_id = i.currency_id and
+ cr.company_id = i.company_id and
+ cr.date_start <= COALESCE(i.date_invoice, NOW()) and
+ (cr.date_end IS NULL OR cr.date_end > COALESCE(i.date_invoice, NOW())))
where l.product_id = %s and i.state in %s and i.type IN %s and (i.date_invoice IS NULL or (i.date_invoice>=%s and i.date_invoice<=%s and i.company_id=%s))
- """
+ """.format(self.env['res.currency']._select_companies_rates())
invoice_types = ('out_invoice', 'in_refund')
self.env.cr.execute(sqlstr, (val.id, states, invoice_types, date_from, date_to, company_id))
result = self.env.cr.fetchall()[0]