diff options
| author | Achraf (abz) <abz@odoo.com> | 2021-04-08 05:27:35 +0000 |
|---|---|---|
| committer | Achraf (abz) <abz@odoo.com> | 2021-04-09 05:00:55 +0000 |
| commit | 675feb254ed3448571818a77c920012cbd066c8b (patch) | |
| tree | d1ab594101b1600b5eea5bb83bc97b87fb300b27 /odoo | |
| parent | f83f523b00e62bb0aec65f6676ef24d585aa8a1d (diff) | |
[FIX] base: Traceback with address layout in reports
What are the steps to reproduce your issue ?
1. Go to Contacts > Configuration > Localization > Countries > Select a country
2. Edit the 'Layout in reports' (enable debug mode) and add an invalid field
3. Create a Quotation and search for a customer from the country you edited.
What is currently happening ?
Traceback is raised and you can't select the customer anymore
Why is this happening ?
Because the key is not defined.
How to fix the bug ?
Handle KeyError to detect if the user put an undefined key
Handle ValueError to detect if the user put an invalid format key
opw-2447078
closes odoo/odoo#68974
X-original-commit: 7d6529fa91062393a257ffbf01c4fd09e2f128bd
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
Signed-off-by: Achraf <abz-odoo@users.noreply.github.com>
Diffstat (limited to 'odoo')
| -rw-r--r-- | odoo/addons/base/i18n/base.pot | 6 | ||||
| -rw-r--r-- | odoo/addons/base/models/res_country.py | 10 |
2 files changed, 16 insertions, 0 deletions
diff --git a/odoo/addons/base/i18n/base.pot b/odoo/addons/base/i18n/base.pot index c53143ee864..6dd0694ecdf 100644 --- a/odoo/addons/base/i18n/base.pot +++ b/odoo/addons/base/i18n/base.pot @@ -23416,6 +23416,12 @@ 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." msgstr "" 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" |
