Cédric Krier pushed to branch branch/default at Tryton / Tryton
Commits:
a91e1a9f by Cédric Krier at 2023-06-08T18:42:07+02:00
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
- - - - -
3 changed files:
- trytond/trytond/model/modelstorage.py
- trytond/trytond/tests/export_data.py
- trytond/trytond/tests/test_exportdata.py
Changes:
=====================================
trytond/trytond/model/modelstorage.py
=====================================
@@ -737,10 +737,11 @@
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:
=====================================
trytond/trytond/tests/export_data.py
=====================================
@@ -9,6 +9,7 @@
"Export Data Target"
__name__ = 'test.export_data.target'
name = fields.Char('Name')
+ value = fields.Float("Value")
class ExportData(ModelSQL):
=====================================
trytond/trytond/tests/test_exportdata.py
=====================================
@@ -355,6 +355,26 @@
[[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'
pool = Pool()
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/commit/a91e1a9f95ca2b22d4ce5372b1753999d03aa8af
--
View it on Heptapod:
https://foss.heptapod.net/tryton/tryton/-/commit/a91e1a9f95ca2b22d4ce5372b1753999d03aa8af
You're receiving this email because of your account on foss.heptapod.net.