From ce5b81315b9284bc791b8cd33d93d18fc209828d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20=28avd=29?= Date: Fri, 12 Feb 2021 09:24:03 +0000 Subject: [PATCH] [FIX] l10n_in: improve perfs of l10n_in invoice report. Slightly change the view of account_invoice_report to add a CTE to prefilter rows before joining with account_move_line. Add a multicolumn for (product_id, move_id) on account_move_line to speed-up cess_amount computation. closes odoo/odoo#77952 X-original-commit: 7b743fbb7a98c45f12979c6c5ac7baa7c34d421a Signed-off-by: Josse Colpaert --- addons/l10n_in/models/account.py | 4 ++++ addons/l10n_in/report/account_invoice_report.py | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/addons/l10n_in/models/account.py b/addons/l10n_in/models/account.py index f07c50afaf2..8533804ee00 100644 --- a/addons/l10n_in/models/account.py +++ b/addons/l10n_in/models/account.py @@ -3,6 +3,7 @@ from odoo import api, fields, models, _ from odoo.exceptions import ValidationError +from odoo import tools class AccountJournal(models.Model): @@ -30,6 +31,9 @@ class AccountJournal(models.Model): class AccountMoveLine(models.Model): _inherit = "account.move.line" + def init(self): + tools.create_index(self._cr, 'account_move_line_move_product_index', self._table, ['move_id', 'product_id']) + @api.depends('move_id.line_ids', 'move_id.line_ids.tax_line_id', 'move_id.line_ids.debit', 'move_id.line_ids.credit') def _compute_tax_base_amount(self): aml = self.filtered(lambda l: l.company_id.account_fiscal_country_id.code == 'IN' and l.tax_line_id and l.product_id) diff --git a/addons/l10n_in/report/account_invoice_report.py b/addons/l10n_in/report/account_invoice_report.py index 59a86695795..a3deb7f4ee2 100644 --- a/addons/l10n_in/report/account_invoice_report.py +++ b/addons/l10n_in/report/account_invoice_report.py @@ -221,12 +221,17 @@ class L10nInAccountInvoiceReport(models.Model): THEN aml.balance ELSE 0 END AS sgst_amount, - (SELECT sum(temp_aml.balance) from account_move_line temp_aml + (WITH account_tax_temp_table AS ( + SELECT account_account_tag_id + FROM account_tax_report_line_tags_rel + WHERE account_tax_report_line_id IN + (SELECT res_id FROM ir_model_data where module='l10n_in' AND name in ('tax_report_line_cess', 'tax_report_line_cess_rc')) + ) + SELECT sum(temp_aml.balance) from account_move_line temp_aml JOIN account_account_tag_account_move_line_rel aat_aml_rel_temp ON aat_aml_rel_temp.account_move_line_id = temp_aml.id JOIN account_account_tag aat_temp ON aat_temp.id = aat_aml_rel_temp.account_account_tag_id - JOIN account_tax_report_line_tags_rel tag_rep_ln_temp ON aat_temp.id = tag_rep_ln_temp.account_account_tag_id + JOIN account_tax_temp_table tag_rep_ln_temp ON aat_temp.id = tag_rep_ln_temp.account_account_tag_id where temp_aml.move_id = aml.move_id and temp_aml.product_id = aml.product_id - and tag_rep_ln_temp.account_tax_report_line_id IN (SELECT res_id FROM ir_model_data WHERE module='l10n_in' AND name in ('tax_report_line_cess', 'tax_report_line_cess_rc')) ) AS cess_amount, CASE WHEN tag_rep_ln.account_tax_report_line_id IN (SELECT res_id FROM ir_model_data WHERE module='l10n_in' AND name in ('tax_report_line_sgst', 'tax_report_line_sgst_rc'))