[ADD] 'more info' action to m2o, o2m and m2m linking failures

bzr revid: xmo@openerp.com-20120925074256-18puerjbfo3om265
This commit is contained in:
Xavier Morel 2012-09-25 09:42:56 +02:00
parent 9f2e7ba7ef
commit e6c8f1739a
2 changed files with 38 additions and 35 deletions

View File

@ -201,6 +201,21 @@ class ir_fields_converter(orm.Model):
id, _name = ids[0]
else:
raise Exception(u"Unknown sub-field '%s'" % subfield)
if id is None:
raise ValueError(
_(u"No matching record found for %(field_type)s '%(value)s' in field '%%(field)s'")
% {'field_type': field_type, 'value': value}, {
'moreinfo': {
'type': 'ir.actions.act_window',
'target': 'new',
'res_model': column._obj,
'view_mode': 'tree,form',
'view_type': 'form',
'views': [(False, 'tree', (False, 'form'))],
'help': _(u"See all possible values")
}
})
return id, field_type
def _referencing_subfield(self, record):
@ -235,12 +250,8 @@ class ir_fields_converter(orm.Model):
reference = record[subfield]
id, subfield_type = self.db_id_for(
cr, uid, model, column, subfield, reference, context=context)
if id is None:
raise ValueError(
_(u"No matching record found for %(field_type)s '%(value)s' in field '%%(field)s'")
% {'field_type': subfield_type, 'value': reference})
return id
def _str_to_many2many(self, cr, uid, model, column, value, context=None):
[record] = value
@ -250,13 +261,9 @@ class ir_fields_converter(orm.Model):
for reference in record[subfield].split(','):
id, subfield_type = self.db_id_for(
cr, uid, model, column, subfield, reference, context=context)
if id is None:
raise ValueError(
_(u"No matching record found for %(field_type)s '%(value)s' in field '%%(field)s'")
% {'field_type': subfield_type, 'value': reference})
ids.append(id)
return [(6, 0, ids)]
def _str_to_one2many(self, cr, uid, model, column, records, context=None):
commands = []
@ -278,10 +285,6 @@ class ir_fields_converter(orm.Model):
reference = record[subfield]
id, subfield_type = self.db_id_for(
cr, uid, model, column, subfield, reference, context=context)
if id is None:
raise ValueError(
_(u"No matching record found for %(field_type)s '%(value)s' in field '%%(field)s'")
% {'field_type': subfield_type, 'value': reference})
writable = exclude_ref_fields(record)
if id:

View File

@ -9,18 +9,16 @@ def message(msg, type='error', from_=0, to_=0, record=0, field='value', **kwargs
return dict(kwargs,
type=type, rows={'from': from_, 'to': to_}, record=record,
field=field, message=msg)
def error(row, message, record=None, **kwargs):
""" Failed import of the record ``record`` at line ``row``, with the error
message ``message``
:param str message:
:param dict record:
"""
return (
-1, dict(record or {}, **kwargs),
"Line %d : %s" % (row, message),
'')
def moreaction(model):
return {
'type': 'ir.actions.act_window',
'target': 'new',
'res_model': model,
'view_mode': 'tree,form',
'view_type': 'form',
'views': [(False, 'tree', (False, 'form'))],
'help': u"See all possible values"
}
def values(seq, field='value'):
return [item[field] for item in seq]
@ -596,7 +594,8 @@ class test_m2o(ImporterCase):
])
self.assertEqual(result['messages'], [
message(u"No matching record found for name '%s' in field 'unknown'" % id,
from_=index, to_=index, record=index)
from_=index, to_=index, record=index,
moreinfo=moreaction('export.integer'))
for index, id in enumerate([integer_id1, integer_id2, integer_id1])])
self.assertIs(result['ids'], False)
@ -614,19 +613,19 @@ class test_m2o(ImporterCase):
result = self.import_(['value'], [['nameisnoexist:3']])
self.assertEqual(result['messages'], [message(
u"No matching record found for name 'nameisnoexist:3' "
u"in field 'unknown'")])
u"in field 'unknown'", moreinfo=moreaction('export.integer'))])
self.assertIs(result['ids'], False)
result = self.import_(['value/id'], [['noxidhere']])
self.assertEqual(result['messages'], [message(
u"No matching record found for external id 'noxidhere' "
u"in field 'unknown'")])
u"in field 'unknown'", moreinfo=moreaction('export.integer'))])
self.assertIs(result['ids'], False)
result = self.import_(['value/.id'], [['66']])
self.assertEqual(result['messages'], [message(
u"No matching record found for database id '66' "
u"in field 'unknown'")])
u"in field 'unknown'", moreinfo=moreaction('export.integer'))])
self.assertIs(result['ids'], False)
def test_fail_multiple(self):
@ -678,7 +677,7 @@ class test_m2m(ImporterCase):
result = self.import_(['value/.id'], [['42']])
self.assertEqual(result['messages'], [message(
u"No matching record found for database id '42' in field "
u"'unknown'")])
u"'unknown'", moreinfo=moreaction('export.many2many.other'))])
self.assertIs(result['ids'], False)
def test_xids(self):
@ -703,8 +702,8 @@ class test_m2m(ImporterCase):
def test_noxids(self):
result = self.import_(['value/id'], [['noxidforthat']])
self.assertEqual(result['messages'], [message(
u"No matching record found for external id 'noxidforthat' "
u"in field 'unknown'")])
u"No matching record found for external id 'noxidforthat' in field"
u" 'unknown'", moreinfo=moreaction('export.many2many.other'))])
self.assertIs(result['ids'], False)
def test_names(self):
@ -733,7 +732,7 @@ class test_m2m(ImporterCase):
result = self.import_(['value'], [['wherethem2mhavenonames']])
self.assertEqual(result['messages'], [message(
u"No matching record found for name 'wherethem2mhavenonames' in "
u"field 'unknown'")])
u"field 'unknown'", moreinfo=moreaction('export.many2many.other'))])
self.assertIs(result['ids'], False)
def test_import_to_existing(self):
@ -766,7 +765,8 @@ class test_o2m(ImporterCase):
['const', 'value'],
[['5', s]])
self.assertEqual(result['messages'], [message(
u"No matching record found for name '%s' in field 'unknown'" % s)])
u"No matching record found for name '%s' in field 'unknown'" % s,
moreinfo=moreaction('export.one2many.child'))])
self.assertIs(result['ids'], False)
def test_single(self):