[IMP] use moreinfo key to provide more info as to what the boolean and date value should look like

bzr revid: xmo@openerp.com-20121004123237-p5ht1uozaobxn8b7
This commit is contained in:
Xavier Morel 2012-10-04 14:32:37 +02:00
parent e77fad774b
commit 67a9cf851c
2 changed files with 14 additions and 8 deletions

View File

@ -99,7 +99,9 @@ class ir_fields_converter(orm.Model):
return True, [orm.ImportWarning(
_(u"Unknown value '%s' for boolean field '%%(field)s', assuming '%s'")
% (value, yes))]
% (value, yes), {
'moreinfo': _(u"Use '1' for yes and '0' for no")
})]
def _str_to_integer(self, cr, uid, model, column, value, context=None):
try:
@ -127,8 +129,9 @@ class ir_fields_converter(orm.Model):
return value, []
except ValueError:
raise ValueError(
_(u"'%s' does not seem to be a valid date for field '%%(field)s'. Use the format '%s'") %
(value, u"2012-12-31"))
_(u"'%s' does not seem to be a valid date for field '%%(field)s'") % value, {
'moreinfo': _(u"Use the format '%s'") % u"2012-12-31"
})
def _str_to_datetime(self, cr, uid, model, column, value, context=None):
try:
@ -136,8 +139,9 @@ class ir_fields_converter(orm.Model):
return value, []
except ValueError:
raise ValueError(
_(u"'%s' does not seem to be a valid datetime for field '%%(field)s'. Use the format '%s'") %
(value, u"2012-12-31 23:59:59"))
_(u"'%s' does not seem to be a valid datetime for field '%%(field)s'") % value, {
'moreinfo': _(u"Use the format '%s'") % u"2012-12-31 23:59:59"
})
def _get_translations(self, cr, uid, types, src, context):
types = tuple(types)

View File

@ -184,6 +184,7 @@ class test_boolean_field(ImporterCase):
self.assertEqual(len(result['ids']), 10)
self.assertEqual(result['messages'], [
message(u"Unknown value '%s' for boolean field 'unknown', assuming 'yes'" % v[0],
moreinfo=u"Use '1' for yes and '0' for no",
type='warning', from_=i, to_=i, record=i)
for i, v in enumerate(trues)
if v[0] not in ('true', 'yes', '1')
@ -1008,7 +1009,8 @@ class test_date(ImporterCase):
result = self.import_(['value'], [['not really a date']])
self.assertEqual(result['messages'], [
message(u"'not really a date' does not seem to be a valid date "
u"for field 'unknown'. Use the format '2012-12-31'")])
u"for field 'unknown'",
moreinfo=u"Use the format '2012-12-31'")])
self.assertIs(result['ids'], False)
class test_datetime(ImporterCase):
@ -1028,8 +1030,8 @@ class test_datetime(ImporterCase):
result = self.import_(['value'], [['not really a datetime']])
self.assertEqual(result['messages'], [
message(u"'not really a datetime' does not seem to be a valid "
u"datetime for field 'unknown'. Use the format "
u"'2012-12-31 23:59:59'")])
u"datetime for field 'unknown'",
moreinfo=u"Use the format '2012-12-31 23:59:59'")])
self.assertIs(result['ids'], False)
# function, related, reference: written to db as-is...