[CHG] make empty cells clear out the corresponding field on import, rather than skip them

bzr revid: xmo@openerp.com-20121009092519-ge86yp3nnkqe9gic
This commit is contained in:
Xavier Morel 2012-10-09 11:25:19 +02:00
parent 10345423b1
commit 510eea5305
3 changed files with 17 additions and 4 deletions

View File

@ -1496,6 +1496,7 @@ class BaseModel(object):
for field, strvalue in record.iteritems():
if field in (None, 'id', '.id'): continue
if not strvalue:
converted[field] = False
continue
# In warnings and error messages, use translated string as

View File

@ -128,8 +128,10 @@ class SelectionWithDefault(orm.Model):
_name = 'export.selection.withdefault'
_columns = {
'value': fields.selection([(1, "Foo"), (2, "Bar")], required=True),
'const': fields.integer(),
'value': fields.selection([(1, "Foo"), (2, "Bar")]),
}
_defaults = {
'const': 4,
'value': 2,
}

View File

@ -476,14 +476,24 @@ class test_selection(ImporterCase):
class test_selection_with_default(ImporterCase):
model_name = 'export.selection.withdefault'
def test_skip_empty(self):
""" Empty cells should be entirely skipped so that default values can
be inserted by the ORM
def test_empty(self):
""" Empty cells should set corresponding field to False
"""
result = self.import_(['value'], [['']])
self.assertFalse(result['messages'])
self.assertEqual(len(result['ids']), 1)
self.assertEqual(
values(self.read()),
[False])
def test_default(self):
""" Non-provided cells should set corresponding field to default
"""
result = self.import_(['const'], [['42']])
self.assertFalse(result['messages'])
self.assertEqual(len(result['ids']), 1)
self.assertEqual(
values(self.read()),
[2])