Skip to content

Commit 3f1f830

Browse files
committed
[FIX] util.update_record_from_xml: correctly handle from_module
When loading a record from another module, we should only search for fully-qualified xmlids. Part-of: odoo/upgrade#5267
1 parent a258178 commit 3f1f830

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/base/tests/test_util.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,26 @@ def test_update_record_translations_from_xml(self):
737737
for fname, value in field_to_value.items():
738738
self.assertEqual(template_record.with_context(lang=lang)[fname], value)
739739

740+
def test_update_record_from_xml__from_module(self):
741+
cr = self.env.cr
742+
if not util.module_installed(cr, "web"):
743+
self.skip()
744+
745+
layout = self.env.ref("web.report_layout")
746+
new_name = str(uuid.uuid4())
747+
748+
layout.write({"name": new_name})
749+
util.flush(layout)
750+
util.invalidate(layout)
751+
752+
# the record `base.report_layout` does not exists, so we must pass the `force_create`.
753+
# we only test that it won't update `web.report_layout`.
754+
util.update_record_from_xml(cr, "base.report_layout", from_module="web", force_create=True)
755+
util.invalidate(layout)
756+
757+
# web.layout should NOT have been updated
758+
self.assertEqual(layout.name, new_name)
759+
740760
def test_ensure_xmlid_match_record(self):
741761
cr = self.env.cr
742762
tx1 = self.env["res.currency"].create({"name": "TX1", "symbol": "TX1"})

src/util/records.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,11 +749,18 @@ def update_record_from_xml(
749749
cr.execute("SELECT write_uid, write_date, id FROM {} WHERE id=%s".format(table), [res_id])
750750
write_data = cr.fetchone()
751751

752-
xpath = "//*[@id='{module}.{name}' or @id='{name}']".format(module=module, name=name)
752+
from_module = from_module or module
753+
754+
id_match = (
755+
"@id='{module}.{name}' or @id='{name}'".format(module=module, name=name)
756+
if module == from_module
757+
else "@id='{module}.{name}'".format(module=module, name=name)
758+
)
759+
xpath = "//*[{}]".format(id_match)
760+
753761
# use a data tag inside openerp tag to be compatible with all supported versions
754762
new_root = lxml.etree.fromstring("<openerp><data/></openerp>")
755763

756-
from_module = from_module or module
757764
manifest = get_manifest(from_module)
758765
template = False
759766
extra_references = []

0 commit comments

Comments
 (0)