Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/util/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,8 @@ def update_record_from_xml(
should also be updated.
:param set(str) or None fields: optional list of fields to include in the XML declaration.
If set, all other fields will be ignored. When set, record
won't be created if missing.
won't be created if missing and all fields not found in
the XML declaration will be set to NULL.

.. warning::
This functions uses the ORM, therefore it can only be used after **all** models
Expand Down Expand Up @@ -1147,9 +1148,21 @@ def add_ref(ref):
found = True
parent = node.getparent()
if node.tag == "record" and fields is not None:
xml_fields = set()
for fn in node.xpath("./field[@name]"):
if fn.attrib["name"] not in fields:
node.remove(fn)
xml_fields.add(fn.attrib["name"])
# override requested fields not found in xml
fields_default = env(cr)[node.attrib["model"]].default_get(fields)
for field in fields:
if field not in xml_fields:
field_default = fields_default.get(field)
if field_default is None:
node.append(lxml.builder.E.field(name=field, eval="False"))
else:
node.append(lxml.builder.E.field(str(field_default), name=field))

new_root[0].append(node)

if node.tag == "menuitem" and parent.tag == "menuitem" and "parent_id" not in node.attrib:
Expand Down