[FIX] don't import empty cells at all rather than set them to False, to allow defaults handling to do its job before actually creating the record
bzr revid: xmo@openerp.com-20121004064215-fqgir3ovmte2v438
This commit is contained in:
parent
b9b19f61ea
commit
601568f5f9
|
@ -1501,7 +1501,6 @@ 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
|
||||
|
|
|
@ -123,3 +123,13 @@ class Many2ManyChild(orm.Model):
|
|||
, context=context)
|
||||
if isinstance(name, basestring) and name.split(':')[0] == self._name
|
||||
else [])
|
||||
|
||||
class SelectionWithDefault(orm.Model):
|
||||
_name = 'export.selection.withdefault'
|
||||
|
||||
_columns = {
|
||||
'value': fields.selection([(1, "Foo"), (2, "Bar")], required=True),
|
||||
}
|
||||
_defaults = {
|
||||
'value': 2,
|
||||
}
|
||||
|
|
|
@ -474,6 +474,21 @@ class test_selection(ImporterCase):
|
|||
u"Value '42' not found in selection field 'unknown'",
|
||||
moreinfo="Foo Bar Qux 4".split())])
|
||||
|
||||
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
|
||||
"""
|
||||
result = self.import_(['value'], [['']])
|
||||
self.assertFalse(result['messages'])
|
||||
self.assertEqual(len(result['ids']), 1)
|
||||
|
||||
self.assertEqual(
|
||||
values(self.read()),
|
||||
[2])
|
||||
|
||||
class test_selection_function(ImporterCase):
|
||||
model_name = 'export.selection.function'
|
||||
translations_fr = [
|
||||
|
|
Loading…
Reference in New Issue