[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) <xmo@odoo.com>
Signed-off-by: Hubert Van De Walle <huvw@odoo.com>
This commit is contained in:
Hubert Van de Walle (huvw)
2022-01-17 06:42:47 +00:00
parent 8f7c6997e8
commit f1f4d81d37
3 changed files with 14 additions and 14 deletions
+1 -1
View File
@@ -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):
+10 -10
View File
@@ -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(
+3 -3
View File
@@ -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):