From 90eac45ba9023f1971a156eb794fd7880cee31aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 8 Jun 2023 18:42:07 +0200 Subject: [PATCH] Skip child position of exported data based on field names When exporting data of a xxx2Many field, the column to skip should be based on the child field names instead of the exported value (which can be 0 for example). Closes #12316 (grafted from a91e1a9f95ca2b22d4ce5372b1753999d03aa8af) --HG-- branch : 6.0 --- trytond/trytond/model/modelstorage.py | 9 +++++---- trytond/trytond/tests/export_data.py | 1 + trytond/trytond/tests/test_exportdata.py | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) 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'