diff --git a/odoo/addons/base/i18n/base.pot b/odoo/addons/base/i18n/base.pot index 697ee2396cf..763f4b7e69e 100644 --- a/odoo/addons/base/i18n/base.pot +++ b/odoo/addons/base/i18n/base.pot @@ -23383,6 +23383,12 @@ msgstr "" msgid "The internal user in charge of this contact." msgstr "" +#. module: base +#: code:addons/base/models/res_country.py:106 +#, python-format +msgid "The layout contains an invalid format key" +msgstr "" + #. module: base #: model:ir.model.fields,help:base.field_ir_model__inherited_model_ids msgid "The list of models that extends the current model." diff --git a/odoo/addons/base/models/res_country.py b/odoo/addons/base/models/res_country.py index dfcf758bdbd..9bbbbe359e1 100644 --- a/odoo/addons/base/models/res_country.py +++ b/odoo/addons/base/models/res_country.py @@ -5,6 +5,7 @@ import re import logging from odoo import api, fields, models from odoo.osv import expression +from odoo.exceptions import UserError from psycopg2 import IntegrityError from odoo.tools.translate import _ _logger = logging.getLogger(__name__) @@ -120,6 +121,15 @@ class Country(models.Model): code = FLAG_MAPPING.get(country.code, country.code.lower()) country.image_url = "/base/static/img/country_flags/%s.png" % code + @api.constrains('address_format') + def _check_address_format(self): + for record in self: + if record.address_format: + address_fields = self.env['res.partner']._formatting_address_fields() + ['state_code', 'state_name', 'country_code', 'country_name', 'company_name'] + try: + record.address_format % {i: 1 for i in address_fields} + except (ValueError, KeyError): + raise UserError(_('The layout contains an invalid format key')) class CountryGroup(models.Model): _description = "Country Group"