Support export of xxx2many fields as list of name

This commit is contained in:
Cédric Krier
2025-05-21 17:00:31 +02:00
parent 9843587815
commit eab2b6deb0
3 changed files with 34 additions and 18 deletions
+1
View File
@@ -1,3 +1,4 @@
* Support export of xxx2many fields as list of name
* Set Message-Id to email sent
* Add pair/unpair in tools
+19 -16
View File
@@ -903,23 +903,26 @@ class ModelStorage(Model):
first = True
child_fields_names = [(x[:i + 1] == fields_tree[:i + 1]
and x[i + 1:]) or [] for x in fields_names]
if child_fields_names in done:
if any(child_fields_names):
if child_fields_names in done:
break
done.append(child_fields_names)
for child_record in value:
child_lines = child_record.__export_row(
child_fields_names)
if first:
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:
lines += child_lines
break
done.append(child_fields_names)
for child_record in value:
child_lines = child_record.__export_row(
child_fields_names)
if first:
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:
lines += child_lines
break
else:
value = [r.rec_name for r in value]
i += 1
if i == len(fields_tree):
if value is None:
+14 -2
View File
@@ -322,6 +322,10 @@ class ExportDataTestCase(TestCase):
ExportData.export_data([export1], ['many2one/name']),
[['Target Test']])
self.assertEqual(
ExportData.export_data([export1], ['many2one']),
[['Target Test']])
export2, = ExportData.create([{
'many2one': None,
}])
@@ -374,6 +378,10 @@ class ExportDataTestCase(TestCase):
['id', 'many2many/name']),
[[export1.id, 'Target 1'], ['', 'Target 2'], [export2.id, '']])
self.assertEqual(
ExportData.export_data([export1], ['id', 'many2many']),
[[export1.id, 'Target 1,Target 2']])
@with_transaction()
def test_one2many(self):
'Test export_data one2many'
@@ -409,6 +417,10 @@ class ExportDataTestCase(TestCase):
'one2many/name']),
[[export1.id, 'Target 1'], ['', 'Target 2'], [export2.id, '']])
self.assertEqual(
ExportData.export_data([export1], ['id', 'one2many']),
[[export1.id, 'Target 1,Target 2']])
@with_transaction()
def test_one2many_empty_value(self):
"Test export_data one2many with first child with 0 value"
@@ -442,7 +454,7 @@ class ExportDataTestCase(TestCase):
}])
self.assertEqual(
ExportData.export_data([export1], ['reference']),
[[str(target1)]])
[['test.export_data.target,' + target1.rec_name]])
export2, = ExportData.create([{
'reference': None,
@@ -453,7 +465,7 @@ class ExportDataTestCase(TestCase):
self.assertEqual(
ExportData.export_data([export1, export2],
['reference']),
[[str(target1)], ['']])
[['test.export_data.target,' + target1.rec_name], ['']])
self.assertEqual(
ExportData.export_data([export1], ['reference/rec_name']),