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):