Skip to content
Snippets Groups Projects
Commit 64358d3332b7 authored by Christophe de Vienne's avatar Christophe de Vienne
Browse files

export: Fix deep relations

parent ac35cc40b8b7
No related branches found
No related tags found
No related merge requests found
......@@ -71,4 +71,6 @@
if source is not None:
path = source.split(".")
cur_fields = fields
for i, fname in enumerate(path):
......@@ -74,6 +76,6 @@
for i, fname in enumerate(path):
field = fields[fname]
field = cur_fields[fname]
value_datatype = field["type"]
value = getattr(value, fname)
......@@ -76,13 +78,15 @@
value_datatype = field["type"]
value = getattr(value, fname)
if (
field["type"] in ("many2one", "many2many", "one2many")
and len(value) == 0
):
value = None
break
if field["type"] in ("many2one", "many2many", "one2many"):
cur_fields = value.fields_get()
if len(value) == 0:
value = None
break
# TODO for 2many relations, keep all the values
if i != len(path) - 1:
value = value[0]
if field["type"] in ("char", "text") and value is False:
value = None
......
......@@ -111,6 +111,26 @@
export(record, m),
)
def test_export_deep_relation(self):
m = {
"company": {
"source": "partner_ids.company_id",
"mapping": {"name": {}},
}
}
c1 = self.env["res.partner.category"].create({"name": "cat1"})
company = self.env["res.company"].create({"name": "company"})
p1 = self.env["res.partner"].create(
{"name": "partner 1", "company_id": company.id}
)
c1.partner_ids = [p1.id]
self.assertEqual({"company": {"name": "company"}}, export(c1, m))
def test_export_custom_char(self):
record = self.env["res.partner"].create({"name": "my name"})
self.assertEqual(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment