diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index ce605b6bba..c02ef3e535 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Support export of xxx2many fields as list of name * Set Message-Id to email sent * Add pair/unpair in tools diff --git a/trytond/trytond/model/modelstorage.py b/trytond/trytond/model/modelstorage.py index 4239356584..1844c825a1 100644 --- a/trytond/trytond/model/modelstorage.py +++ b/trytond/trytond/model/modelstorage.py @@ -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: diff --git a/trytond/trytond/tests/test_exportdata.py b/trytond/trytond/tests/test_exportdata.py index b42327624a..a317dc2b7b 100644 --- a/trytond/trytond/tests/test_exportdata.py +++ b/trytond/trytond/tests/test_exportdata.py @@ -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']),