summaryrefslogtreecommitdiff
path: root/addons/product_margin
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2019-07-24 07:36:59 +0000
committerMartin Trigaux <mat@odoo.com>2019-07-24 10:32:23 +0000
commita98427834e00380e2e63e08668f5c2b069e3c2ea (patch)
treefbefd4a26124efbaf5e6b4bdbf58ec570014c896 /addons/product_margin
parent4e6ee3ac97041653ff15a77abd77084dc0c9f525 (diff)
parent860ab5a1c28ba85d7a193d68cfbbb1063bbf0651 (diff)
[MERGE] Forward port of saas-12.2 to saas-12.3 up to 860ab5a1c28ba
closes odoo/odoo#35119 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
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 f9f01236fda..1f34440a23d 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]