From fbdc298303334b54f1e7f1cad7ac8af71fc0ce8e Mon Sep 17 00:00:00 2001 From: moerradi Date: Tue, 26 Sep 2023 11:52:55 +0100 Subject: [PATCH] [IMP] account: make account tags unique mplemented a uniqueness constraint for account tags name, applicability and country_id to allow some localizations to use tags over account codes. Task-3497548 closes odoo/odoo#136639 Related: odoo/upgrade#5240 Signed-off-by: John Laterre (jol) --- addons/account/models/account_account_tag.py | 2 ++ addons/account/tests/test_chart_template.py | 4 ++-- addons/l10n_cl/data/account_tax_tags_data.xml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/account/models/account_account_tag.py b/addons/account/models/account_account_tag.py index acb411e2e50..0e94691d2c5 100644 --- a/addons/account/models/account_account_tag.py +++ b/addons/account/models/account_account_tag.py @@ -14,6 +14,8 @@ class AccountAccountTag(models.Model): tax_negate = fields.Boolean(string="Negate Tax Balance", help="Check this box to negate the absolute value of the balance of the lines associated with this tag in tax report computation.") country_id = fields.Many2one(string="Country", comodel_name='res.country', help="Country for which this tag is available, when applied on taxes.") + _sql_constraints = [('name_uniq', "unique(name, applicability, country_id)", "A tag with the same name and applicability already exists in this country.")] + @api.depends('applicability', 'country_id') @api.depends_context('company') def _compute_display_name(self): diff --git a/addons/account/tests/test_chart_template.py b/addons/account/tests/test_chart_template.py index 039f479ba51..e1d2feea92f 100644 --- a/addons/account/tests/test_chart_template.py +++ b/addons/account/tests/test_chart_template.py @@ -40,7 +40,7 @@ def test_get_data(self, template_code): }, }, 'account.account.tag': { - 'account_tax_tag_1': { + 'account.account_tax_tag_1': { 'name': 'tax_tag_name_1', 'applicability': 'taxes', 'country_id': 'base.be', @@ -249,7 +249,7 @@ class TestChartTemplate(TransactionCase): """ When a tax is close enough from an existing tax we want to update that tax with the new values. """ def local_get_data(self, template_code): data = test_get_data(self, template_code) - data['account.account.tag']['account_tax_tag_1']['name'] += ' [DUP]' + data['account.account.tag']['account.account_tax_tag_1']['name'] += ' [DUP]' return data tax_existing = self.env['account.tax'].search([('company_id', '=', self.company_1.id), ('name', '=', 'Tax 1')]) diff --git a/addons/l10n_cl/data/account_tax_tags_data.xml b/addons/l10n_cl/data/account_tax_tags_data.xml index af9b05d074c..4e424d319da 100644 --- a/addons/l10n_cl/data/account_tax_tags_data.xml +++ b/addons/l10n_cl/data/account_tax_tags_data.xml @@ -109,7 +109,7 @@ - Purchases - Amount of Active Fixed VAT (Common Use) + Purchases - Amount of Active Fixed VAT (Non Deductible) taxes