diff --git a/src/util/records.py b/src/util/records.py index 094ebe86b..a5601bd0f 100644 --- a/src/util/records.py +++ b/src/util/records.py @@ -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 @@ -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: