[IMP] base: display full name of the field in import warning

Before this change, if an error occurs while trying to match / import
a sub-field e.g. order_line/product_id, only the name of the top-level
field is showing when displaying the error e.g. "Order Line", which
lacks precision and makes understanding and fixing the issue more
complicated.

After this change, the entire field path should be displayed, e.g.
"Order Line / Product" in the example above.

Task-1906700

closes odoo/odoo#33031

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Co-authored-by: Mohammed Shekha <msh@odoo.com>
This commit is contained in:
Jinal Patel
2020-03-23 11:51:30 +00:00
committed by Xavier Morel
co-authored by Mohammed Shekha
parent 800db7405c
commit 8f8c93b68a
3 changed files with 29 additions and 4 deletions
+7 -4
View File
@@ -452,10 +452,13 @@ class IrFieldsConverter(models.AbstractModel):
# [{subfield:ref1},{subfield:ref2},{subfield:ref3}]
records = ({subfield:item} for item in record[subfield].split(','))
def log(_, e):
if not isinstance(e, Warning):
raise e
warnings.append(e)
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}
exception.args = (arg0, *exception.args[1:])
raise exception
warnings.append(exception)
convert = self.for_model(self.env[field.comodel_name])
+2
View File
@@ -80,6 +80,7 @@ class One2ManyChild(models.Model):
class One2ManyMultiple(models.Model):
_name = 'export.one2many.multiple'
_description = 'Export One To Many Multiple'
_rec_name = 'parent_id'
parent_id = fields.Many2one('export.one2many.recursive')
const = fields.Integer(default=36)
@@ -145,6 +146,7 @@ class SelectionWithDefault(models.Model):
class RecO2M(models.Model):
_name = 'export.one2many.recursive'
_description = 'Export One To Many Recursive'
_rec_name = 'value'
value = fields.Integer()
child = fields.One2many('export.one2many.multiple', 'parent_id')
+20
View File
@@ -887,6 +887,14 @@ class test_o2m(ImporterCase):
values(b.value.sorted(), 'str'),
'this is the rhythm'.split())
def test_subfields_fail_by_implicit_id(self):
result = self.import_(['value/parent_id'], [['noxidforthat']])
self.assertEqual(result['messages'], [message(
u"No matching record found for name 'noxidforthat' in field 'Value/Parent'",
moreinfo=moreaction(res_model='export.one2many')
)])
self.assertIs(result['ids'], False)
def test_link_inline(self):
""" m2m-style specification for o2ms
"""
@@ -1073,6 +1081,18 @@ class test_realworld(SavepointCaseWithUserDemo):
self.assertEqual([child.value for child in b[1].child.sorted()[1].child2],
[12])
def test_o2m_subfields_fail_by_implicit_id(self):
self.env['ir.model.data'].clear_caches()
Model = self.env['export.one2many.recursive']
result = Model.load(
['child/child1/parent_id'],
[['5'],],
)
self.assertEqual(result['messages'], [message(
u"No matching record found for name '5' in field 'Child/Child1/Parent'", field='child',
moreinfo=moreaction(res_model='export.one2many.multiple'))])
self.assertIs(result['ids'], False)
class test_date(ImporterCase):
model_name = 'export.date'