[FIX] temperate error message in case of missing required field

The message worked (ish) for a missing field directly on the model,
but completely broke if the missing field was on an o2m and had the
same name as a field on the model, then it was complete
misinformation.

bzr revid: xmo@openerp.com-20121112084804-zcgtpml3a19uv909
This commit is contained in:
Xavier Morel
2012-11-12 09:48:04 +01:00
parent 75903aec86
commit be03940d64
2 changed files with 15 additions and 8 deletions
+9 -6
View File
@@ -5216,14 +5216,17 @@ def convert_pgerror_23502(model, fields, info, e):
m = re.match(r'^null value in column "(?P<field>\w+)" violates '
r'not-null constraint\n',
str(e))
if not m or m.group('field') not in fields:
field_name = m.group('field')
if not m or field_name not in fields:
return {'message': unicode(e)}
field = fields[m.group('field')]
message = _(u"Missing required value for the field '%s'.") % field_name
field = fields.get(field_name)
if field:
message = _(u"%s This might be '%s' in the current model, or a field "
u"of the same name in an o2m.") % (message, field['string'])
return {
'message': _(u"Missing required value for the field '%(field)s'") % {
'field': field['string']
},
'field': m.group('field'),
'message': message,
'field': field_name,
}
PGERROR_TO_OE = collections.defaultdict(
@@ -393,14 +393,18 @@ class test_required_string_field(ImporterCase):
def test_empty(self):
result = self.import_(['value'], [[]])
self.assertEqual(result['messages'], [message(
u"Missing required value for the field 'unknown'")])
u"Missing required value for the field 'value'. This might be "
u"'unknown' in the current model, or a field of the same name in "
u"an o2m.")])
self.assertIs(result['ids'], False)
@mute_logger('openerp.sql_db', 'openerp.osv.orm')
def test_not_provided(self):
result = self.import_(['const'], [['12']])
self.assertEqual(result['messages'], [message(
u"Missing required value for the field 'unknown'")])
u"Missing required value for the field 'value'. This might be "
u"'unknown' in the current model, or a field of the same name in "
u"an o2m.")])
self.assertIs(result['ids'], False)
class test_text(ImporterCase):