[FIX] purchase: remove unnecessary JOIN in purchase.report

This join is a leftover from https://github.com/odoo/odoo/pull/28248
and is not needed anymore since currency_rate is now stored on purchase.order.
Removing it allows to greatly speedup purchase.report queries.

On a database with 7000 purchase order and 1100 res_currency_rate:

From:
Planning Time: 4.411 ms
Execution Time: 19815.754 ms

To:
Planning Time: 16.914 ms
Execution Time: 77.433 ms

opw-2973044

closes odoo/odoo#104301

X-original-commit: 4ffa967eecfd930da7a0051122ed746af38ce709
Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
This commit is contained in:
nda-odoo
2022-10-27 15:41:18 +02:00
parent c989ff339d
commit 3246fe4d38
+1 -6
View File
@@ -65,7 +65,6 @@ class PurchaseReport(models.Model):
def _select(self):
select_str = """
WITH currency_rate as (%s)
SELECT
po.id as order_id,
min(l.id) as id,
@@ -99,7 +98,7 @@ class PurchaseReport(models.Model):
then sum(l.product_qty / line_uom.factor * product_uom.factor) - sum(l.qty_invoiced / line_uom.factor * product_uom.factor)
else sum(l.qty_received / line_uom.factor * product_uom.factor) - sum(l.qty_invoiced / line_uom.factor * product_uom.factor)
end as qty_to_be_billed
""" % self.env['res.currency']._select_companies_rates()
"""
return select_str
def _from(self):
@@ -112,10 +111,6 @@ class PurchaseReport(models.Model):
left join product_template t on (p.product_tmpl_id=t.id)
left join uom_uom line_uom on (line_uom.id=l.product_uom)
left join uom_uom product_uom on (product_uom.id=t.uom_id)
left join currency_rate cr on (cr.currency_id = po.currency_id and
cr.company_id = po.company_id and
cr.date_start <= coalesce(po.date_order, now()) and
(cr.date_end is null or cr.date_end > coalesce(po.date_order, now())))
left join {currency_table} ON currency_table.company_id = po.company_id
""".format(
currency_table=self.env['res.currency']._get_query_currency_table({'multi_company': True, 'date': {'date_to': fields.Date.today()}}),