[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 <jco@openerp.com>
This commit is contained in:
Aurélien (avd)
2021-10-06 12:39:54 +00:00
parent e3405031ba
commit ce5b81315b
2 changed files with 12 additions and 3 deletions
+4
View File
@@ -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)
@@ -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'))