summaryrefslogtreecommitdiff
path: root/odoo/addons
diff options
context:
space:
mode:
authorJinal Patel <jip@odoo.com>2019-04-29 04:47:58 +0000
committerXavier Morel <xmo@odoo.com>2020-03-23 11:51:30 +0000
commit8f8c93b68a640f1503aec2c7f9fa1255afbb8aad (patch)
tree2658e9764aea102691cb19e3c182557d2d08331f /odoo/addons
parent800db7405c1fca3d080902562eb62d5072b7d9bb (diff)
[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>
Diffstat (limited to 'odoo/addons')
-rw-r--r--odoo/addons/base/models/ir_fields.py11
-rw-r--r--odoo/addons/test_impex/models.py2
-rw-r--r--odoo/addons/test_impex/tests/test_load.py20
3 files changed, 29 insertions, 4 deletions
diff --git a/odoo/addons/base/models/ir_fields.py b/odoo/addons/base/models/ir_fields.py
index b68aa7c48f5..ec535fb569a 100644
--- a/odoo/addons/base/models/ir_fields.py
+++ b/odoo/addons/base/models/ir_fields.py
@@ -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])
diff --git a/odoo/addons/test_impex/models.py b/odoo/addons/test_impex/models.py
index 296c4677cc3..f5890aec480 100644
--- a/odoo/addons/test_impex/models.py
+++ b/odoo/addons/test_impex/models.py
@@ -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')
diff --git a/odoo/addons/test_impex/tests/test_load.py b/odoo/addons/test_impex/tests/test_load.py
index 3f9774545ae..e69d9d5ca71 100644
--- a/odoo/addons/test_impex/tests/test_load.py
+++ b/odoo/addons/test_impex/tests/test_load.py
@@ -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'