From 9e949bb0bf1554684c924d54e48966ced4742323 Mon Sep 17 00:00:00 2001 From: Brice bib Bartoletti Date: Thu, 23 Mar 2023 17:30:32 +0000 Subject: [PATCH] [REF] account,l10n_eu_oss: query tag easily The aimf of this commit is to make the query of a specific tag with a specific sign easier by avoiding all the filtering in `expression._get_tax_tags().filtered(lambda t: t.tax_negate)` With this commit, we just leverage the existing filtering on domain to only get the desired tag. no-task closes odoo/odoo#117167 X-original-commit: 6eb53a3802d24e283b8334b6f245ffe87dddcbe8 Related: odoo/enterprise#39044 Signed-off-by: Olivier Colson (oco) Signed-off-by: Brice Bartoletti (bib) --- addons/account/models/account_report.py | 4 ++-- addons/account/tests/test_tax_report.py | 2 +- addons/l10n_eu_oss/models/res_company.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/account/models/account_report.py b/addons/account/models/account_report.py index 506aeb29b13..f553953d548 100644 --- a/addons/account/models/account_report.py +++ b/addons/account/models/account_report.py @@ -605,7 +605,7 @@ class AccountReportExpression(models.Model): return totals_by_code - def _get_matching_tags(self): + def _get_matching_tags(self, sign=None): """ Returns all the signed account.account.tags records whose name matches any of the formulas of the tax_tags expressions contained in self. """ tag_expressions = self.filtered(lambda x: x.engine == 'tax_tags') @@ -615,7 +615,7 @@ class AccountReportExpression(models.Model): or_domains = [] for tag_expression in tag_expressions: country = tag_expression.report_line_id.report_id.country_id - or_domains.append(self.env['account.account.tag']._get_tax_tags_domain(tag_expression.formula, country.id)) + or_domains.append(self.env['account.account.tag']._get_tax_tags_domain(tag_expression.formula, country.id, sign)) return self.env['account.account.tag'].with_context(active_test=False).search(osv.expression.OR(or_domains)) diff --git a/addons/account/tests/test_tax_report.py b/addons/account/tests/test_tax_report.py index 9584b1ae923..d82d43b4d2c 100644 --- a/addons/account/tests/test_tax_report.py +++ b/addons/account/tests/test_tax_report.py @@ -185,7 +185,7 @@ class TaxReportTest(AccountTestInvoicingCommon): """ tag_name = "55b" tax_report_line = self._create_basic_tax_report_line(self.tax_report_1, "Line 55 bis", tag_name) - test_tag = tax_report_line.expression_ids._get_matching_tags().filtered(lambda tag: not tag.tax_negate) + test_tag = tax_report_line.expression_ids._get_matching_tags("+") self.env['account.tax.group'].create({ 'name': 'Tax group', 'country_id': self.tax_report_1.country_id.id, diff --git a/addons/l10n_eu_oss/models/res_company.py b/addons/l10n_eu_oss/models/res_company.py index a9f05e0a274..fffce504a67 100644 --- a/addons/l10n_eu_oss/models/res_company.py +++ b/addons/l10n_eu_oss/models/res_company.py @@ -147,7 +147,7 @@ class Company(models.Model): for repartition_line_key, tag_xml_id in tag_for_country.items(): tag = self.env.ref(tag_xml_id) if tag_xml_id else self.env['account.account.tag'] if tag and tag._name == "account.report.expression": - tag = tag._get_matching_tags().filtered(lambda t: not t.tax_negate) + tag = tag._get_matching_tags("+") mapping[repartition_line_key] = tag + oss_tag return mapping