@@ -1013,6 +1013,7 @@ def update_record_from_xml(
1013
1013
from_module = None ,
1014
1014
reset_translations = (),
1015
1015
ensure_references = False ,
1016
+ fields = None ,
1016
1017
):
1017
1018
"""
1018
1019
Update a record based on its definition in the :doc:`/developer/reference/backend/data`.
@@ -1033,6 +1034,8 @@ def update_record_from_xml(
1033
1034
:param set(str) reset_translations: field names whose translations get reset
1034
1035
:param bool ensure_references: whether referred records via `ref` XML attributes
1035
1036
should also be updated.
1037
+ :param set(str) or None fields: optional list of fields to include in the XML declaration.
1038
+ If set, all other fields will be ignored.
1036
1039
1037
1040
.. warning::
1038
1041
This functions uses the ORM, therefore it can only be used after **all** models
@@ -1051,6 +1054,7 @@ def update_record_from_xml(
1051
1054
from_module = from_module ,
1052
1055
reset_translations = reset_translations ,
1053
1056
ensure_references = ensure_references ,
1057
+ fields = fields ,
1054
1058
done_refs = set (),
1055
1059
)
1056
1060
@@ -1063,11 +1067,11 @@ def __update_record_from_xml(
1063
1067
from_module ,
1064
1068
reset_translations ,
1065
1069
ensure_references ,
1070
+ fields ,
1066
1071
done_refs ,
1067
1072
):
1068
1073
from .modules import get_manifest
1069
1074
1070
- # Force update of a record from xml file to bypass the noupdate flag
1071
1075
if "." not in xmlid :
1072
1076
raise ValueError ("Please use fully qualified name <module>.<name>" )
1073
1077
@@ -1095,6 +1099,7 @@ def __update_record_from_xml(
1095
1099
else :
1096
1100
# The xmlid doesn't already exists, nothing to reset
1097
1101
reset_write_metadata = noupdate = reset_translations = False
1102
+ fields = None
1098
1103
1099
1104
write_data = None
1100
1105
if reset_write_metadata :
@@ -1133,6 +1138,10 @@ def add_ref(ref):
1133
1138
for node in doc .xpath (xpath ):
1134
1139
found = True
1135
1140
parent = node .getparent ()
1141
+ if node .tag == "record" and fields is not None :
1142
+ for fn in node .xpath ("./field[@name]" ):
1143
+ if fn .attrib ["name" ] not in fields :
1144
+ node .remove (fn )
1136
1145
new_root [0 ].append (node )
1137
1146
1138
1147
if node .tag == "menuitem" and parent .tag == "menuitem" and "parent_id" not in node .attrib :
@@ -1148,8 +1157,12 @@ def add_ref(ref):
1148
1157
template = True
1149
1158
if ensure_references :
1150
1159
for ref_node in node .xpath ("//field[@ref]" ):
1160
+ if fields is not None and ref_node .attrib ["name" ] not in fields :
1161
+ continue
1151
1162
add_ref (ref_node .get ("ref" ))
1152
1163
for eval_node in node .xpath ("//field[@eval]" ):
1164
+ if fields is not None and eval_node .attrib ["name" ] not in fields :
1165
+ continue
1153
1166
for ref_match in re .finditer (r"\bref\((['\"])(.*?)\1\)" , eval_node .get ("eval" )):
1154
1167
add_ref (ref_match .group (2 ))
1155
1168
@@ -1172,6 +1185,7 @@ def add_ref(ref):
1172
1185
from_module = from_module ,
1173
1186
reset_translations = reset_translations ,
1174
1187
ensure_references = True ,
1188
+ fields = None ,
1175
1189
done_refs = done_refs ,
1176
1190
)
1177
1191
@@ -1189,9 +1203,12 @@ def add_ref(ref):
1189
1203
1190
1204
if reset_translations :
1191
1205
if reset_translations is True :
1192
- fields_with_values_from_xml = {elem .attrib ["name" ] for elem in node .xpath ("//record/field" )}
1193
- if template :
1194
- fields_with_values_from_xml |= {"arch_db" , "name" }
1206
+ if fields is None :
1207
+ fields_with_values_from_xml = {elem .attrib ["name" ] for elem in node .xpath ("//record/field" )}
1208
+ if template :
1209
+ fields_with_values_from_xml |= {"arch_db" , "name" }
1210
+ else :
1211
+ fields_with_values_from_xml = fields
1195
1212
cr .execute (
1196
1213
"SELECT name FROM ir_model_fields WHERE model = %s AND translate = true AND name IN %s" ,
1197
1214
[model , tuple (fields_with_values_from_xml )],
0 commit comments