From eaa2e3b452370a43a427682cab43679d698bf2c9 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 21 Oct 2022 14:24:45 +0000 Subject: [PATCH] [FIX] base: import related field with name containing `%` To reproduce, import and invoice containing one line with a tax of i.e. `21%` on it. Because the message is recursively expanded to follow the relation of the field, the interpolation symbol needs to be escaped every time. Otherwise the message will contain something like > No matching record found for name '21%' in field '%(field)s/Taxes' Where `'21%'` will try to be mistakenly interpolated. X-original-commit: ceb3ce3030b47baa2aca128d364a823becb173ab Part-of: odoo/odoo#104764 --- odoo/addons/base/models/ir_fields.py | 2 +- odoo/addons/test_impex/tests/test_load.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/ir_fields.py b/odoo/addons/base/models/ir_fields.py index 0ed56061caa..ec556509d9e 100644 --- a/odoo/addons/base/models/ir_fields.py +++ b/odoo/addons/base/models/ir_fields.py @@ -604,7 +604,7 @@ class IrFieldsConverter(models.AbstractModel): def log(f, exception): if not isinstance(exception, Warning): current_field_name = self.env[field.comodel_name]._fields[f].string - arg0 = exception.args[0] % {'field': '%(field)s/' + current_field_name} + arg0 = exception.args[0].replace('%(field)s', '%(field)s/' + current_field_name) exception.args = (arg0, *exception.args[1:]) raise exception warnings.append(exception) diff --git a/odoo/addons/test_impex/tests/test_load.py b/odoo/addons/test_impex/tests/test_load.py index b9d365baf61..2a6b506c47d 100644 --- a/odoo/addons/test_impex/tests/test_load.py +++ b/odoo/addons/test_impex/tests/test_load.py @@ -1033,6 +1033,14 @@ class test_o2m(ImporterCase): [b] = self.browse() self.assertEqual(b.value.m2o.value, 101) + def test_escape_m2o_in_o2m(self): + result = self.import_(['value/m2o'], [['21%']]) + self.assertEqual(result['messages'], [message( + u"No matching record found for name '21%' " + u"in field 'Value/M2O'", moreinfo=moreaction( + res_model='export.integer'), + field_name='Value', field_path=['value', 'm2o'], field_type='name', value='21%')]) + class test_o2m_multiple(ImporterCase): model_name = 'export.one2many.multiple'