From f1f4d81d3720dc431a5e2a87eaa61341063a7a5c Mon Sep 17 00:00:00 2001 From: "Hubert Van de Walle (huvw)" Date: Thu, 16 Sep 2021 12:58:44 +0000 Subject: [PATCH] [FIX] web: export empty relational field in xlsx as empty string Steps to follow - Go to the contact app for example - Export some records with a relational field in the import-compatible xlsx format - Reimport the downloaded file - Odoo can't find matching records with a name False Cause of the issue xlsxwriter will write a boolean false value for empty relations Solution If a field is relational, write an empty string instead opw-2643705 closes odoo/odoo#82803 X-original-commit: 510a498aa71f117975a08ca3d3df6217e3b8a74d Signed-off-by: Xavier Morel (xmo) Signed-off-by: Hubert Van De Walle --- addons/test_xlsx_export/tests/test_export.py | 2 +- odoo/addons/test_impex/tests/test_export.py | 20 ++++++++++---------- odoo/models.py | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/addons/test_xlsx_export/tests/test_export.py b/addons/test_xlsx_export/tests/test_export.py index 0eaab615d17..ec96666f2ab 100644 --- a/addons/test_xlsx_export/tests/test_export.py +++ b/addons/test_xlsx_export/tests/test_export.py @@ -267,7 +267,7 @@ class TestGroupedExport(XlsxCreatorCase): [' export.integer:4 (1)' ,''], ['10' ,'export.integer:4'], [' Undefined (1)' ,''], - ['10' ,'False'], + ['10' ,''], ]) def test_nested_records(self): diff --git a/odoo/addons/test_impex/tests/test_export.py b/odoo/addons/test_impex/tests/test_export.py index 6b73b665d05..2b97a281bfb 100644 --- a/odoo/addons/test_impex/tests/test_export.py +++ b/odoo/addons/test_impex/tests/test_export.py @@ -323,7 +323,7 @@ class test_m2o(CreatorCase): def test_empty(self): self.assertEqual( self.export(False), - [[False]]) + [['']]) def test_basic(self): """ Exported value is the name_get of the related object @@ -384,7 +384,7 @@ class test_o2m(CreatorCase): def test_empty(self): self.assertEqual( self.export(False), - [[False]]) + [['']]) def test_single(self): self.assertEqual( @@ -499,16 +499,16 @@ class test_o2m_multiple(CreatorCase): def test_empty(self): self.assertEqual( self.export(child1=False, child2=False), - [[False, False]]) + [['', '']]) def test_single_per_side(self): self.assertEqual( self.export(child1=False, child2=[Command.create({'value': 42})]), - [[False, u'export.one2many.child.2:42']]) + [['', u'export.one2many.child.2:42']]) self.assertEqual( self.export(child1=[Command.create({'value': 43})], child2=False), - [[u'export.one2many.child.1:43', False]]) + [[u'export.one2many.child.1:43', '']]) self.assertEqual( self.export(child1=[Command.create({'value': 43})], @@ -520,12 +520,12 @@ class test_o2m_multiple(CreatorCase): self.assertEqual( self.export(child1=False, child2=[Command.create({'value': 42})], fields=fields), - [[36, False, 42]]) + [[36, '', 42]]) self.assertEqual( self.export(child1=[Command.create({'value': 43})], child2=False, fields=fields), - [[36, 43, False]]) + [[36, 43, '']]) self.assertEqual( self.export(child1=[Command.create({'value': 43})], @@ -546,7 +546,7 @@ class test_o2m_multiple(CreatorCase): self.assertEqual( self.export(child1=child1, child2=False, fields=fields), [ - [36, 4, False], + [36, 4, ''], ['', 42, ''], ['', 36, ''], ['', 4, ''], @@ -555,7 +555,7 @@ class test_o2m_multiple(CreatorCase): self.assertEqual( self.export(child1=False, child2=child2, fields=fields), [ - [36, False, 8], + [36, '', 8], ['', '', 12], ['', '', 8], ['', '', 55], @@ -595,7 +595,7 @@ class test_m2m(CreatorCase): def test_empty(self): self.assertEqual( self.export(False), - [[False]]) + [['']]) def test_single(self): self.assertEqual( diff --git a/odoo/models.py b/odoo/models.py index 199c0df85b8..81c2e1dcf63 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -996,9 +996,9 @@ class BaseModel(metaclass=MetaModel): if name == 'id': xml_ids = [xid for _, xid in value.__ensure_xml_id()] - current[index] = ','.join(xml_ids) or False + current[index] = ','.join(xml_ids) else: - current[index] = field.convert_to_export(value, record) or False + current[index] = field.convert_to_export(value, record) continue lines2 = value._export_rows(fields2, _is_toplevel_call=False) @@ -1010,7 +1010,7 @@ class BaseModel(metaclass=MetaModel): # append the other lines at the end lines += lines2[1:] else: - current[i] = False + current[i] = '' # if any xid should be exported, only do so at toplevel if _is_toplevel_call and any(f[-1] == 'id' for f in fields):