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
This commit is contained in:
Cédric Krier
2023-06-08 18:42:07 +02:00
parent 4bfd3bf0d7
commit 90eac45ba9
3 changed files with 26 additions and 4 deletions
+5 -4
View File
@@ -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:
+1
View File
@@ -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):
+20
View File
@@ -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'