diff --git a/trytond/trytond/model/modelstorage.py b/trytond/trytond/model/modelstorage.py index ac1bffa98f..858f33c875 100644 --- a/trytond/trytond/model/modelstorage.py +++ b/trytond/trytond/model/modelstorage.py @@ -668,10 +668,11 @@ class ModelStorage(Model): child_lines = ModelStorage.__export_row(child_record, child_fields_names) if first: - for child_fpos in range(len(fields_names)): - if child_lines and child_lines[0][child_fpos]: - data[child_fpos] = \ - child_lines[0][child_fpos] + if child_lines: + for child_fpos in range(len(fields_names)): + if child_fields_names[child_fpos]: + data[child_fpos] = ( + child_lines[0][child_fpos]) lines += child_lines[1:] first = False else: diff --git a/trytond/trytond/tests/export_data.py b/trytond/trytond/tests/export_data.py index 67316f93b9..4194978303 100644 --- a/trytond/trytond/tests/export_data.py +++ b/trytond/trytond/tests/export_data.py @@ -9,6 +9,7 @@ class ExportDataTarget(ModelSQL): "Export Data Target" __name__ = 'test.export_data.target' name = fields.Char('Name') + value = fields.Float("Value") class ExportData(ModelSQL): diff --git a/trytond/trytond/tests/test_exportdata.py b/trytond/trytond/tests/test_exportdata.py index 3f6aa9deb4..01cfdf16c8 100644 --- a/trytond/trytond/tests/test_exportdata.py +++ b/trytond/trytond/tests/test_exportdata.py @@ -353,6 +353,26 @@ class ExportDataTestCase(unittest.TestCase): 'one2many/name']), [[export1.id, 'Target 1'], ['', 'Target 2'], [export2.id, '']]) + @with_transaction() + def test_one2many_empty_value(self): + "Test export_data one2many with first child with 0 value" + pool = Pool() + ExportData = pool.get('test.export_data') + ExportDataTarget = pool.get('test.export_data.target') + + export, = ExportData.create([{}]) + ExportDataTarget.create([{ + 'value': 0, + 'one2many': export.id, + }, { + 'value': 42, + 'one2many': export.id, + }]) + + self.assertEqual( + ExportData.export_data([export], ['id', 'one2many/value']), + [[export.id, 0], ['', 42]]) + @with_transaction() def test_reference(self): 'Test export_data reference'