From 0fc9adbe0b20ef783c99dba1810bb534e6fbb216 Mon Sep 17 00:00:00 2001 From: oco-odoo Date: Tue, 3 Mar 2020 15:23:46 +0000 Subject: [PATCH] [IMP] account: tax tags: add a constraint ensuring a country is always set on tax tags The use of such tags was not supported if no country was set on them (we need one to properly filter what to display in tax configuration). We just make it explicit by adding this constraint. closes odoo/odoo#47813 X-original-commit: f76c2d92c58b2055bc906b32d47f192c615a46ed Signed-off-by: oco-odoo Signed-off-by: Laurent Smet --- addons/account/i18n/account.pot | 6 ++++++ addons/account/models/account.py | 6 ++++++ addons/account/tests/test_invoice_taxes.py | 1 + 3 files changed, 13 insertions(+) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 7c6fc1e30bb..1e052d249ab 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -12568,3 +12568,9 @@ msgstr "" #: model_terms:ir.ui.view,arch_db:account.view_bank_statement_form msgid "→ Count" msgstr "" + +#. module: account +#: code:addons/account/models/account.py:56 +#, python-format +msgid "A tag defined to be used on taxes must always have a country set." +msgstr "" diff --git a/addons/account/models/account.py b/addons/account/models/account.py index 224e19d4fbc..fdaf8745619 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -66,6 +66,12 @@ class AccountAccountTag(models.Model): escaped_tag_name = tag_name.replace('\\', '\\\\').replace('%', '\%').replace('_', '\_') return self.env['account.account.tag'].search([('name', '=like', '_' + escaped_tag_name), ('country_id', '=', country_id), ('applicability', '=', 'taxes')]) + @api.constrains('country_id', 'applicability') + def _validate_tag_country(self): + for record in self: + if record.applicability == 'taxes' and not record.country_id: + raise ValidationError(_("A tag defined to be used on taxes must always have a country set.")) + class AccountTaxReport(models.Model): _name = "account.tax.report" diff --git a/addons/account/tests/test_invoice_taxes.py b/addons/account/tests/test_invoice_taxes.py index 63261290b77..0a161f0f7b5 100644 --- a/addons/account/tests/test_invoice_taxes.py +++ b/addons/account/tests/test_invoice_taxes.py @@ -143,6 +143,7 @@ class TestInvoiceTaxes(AccountTestCommon, SavepointCaseWithUserDemo): return self.env['account.account.tag'].create({ 'name': tag_name, 'applicability': 'taxes', + 'country_id': self.env.company.country_id.id, }) def test_tax_repartition(self):