[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
This commit is contained in:
william
2022-11-02 22:20:40 +01:00
committed by william-andre
parent 410ab5ae96
commit eaa2e3b452
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -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)
@@ -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'