Skip to content

Commit a258178

Browse files
committed
[FIX] base/tests: correctly test util.update_record_from_xml
Test the behavior of the `ensure_references` argument in its own function. Trying to update `base.menu_security` with the `ensure_references` flag set will lead to force the update of the `base.main_company` record. This however fail when a localization is installed as it will try to update the company's currency, which is forbidden as some journal items already exist. Part of odoo/upgrade#5256 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 18627f3 commit a258178

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/base/tests/test_util.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import operator
22
import re
33
import unittest
4+
import uuid
45
from ast import literal_eval
56

67
from lxml import etree
@@ -635,14 +636,43 @@ def test_update_record_from_xml_recursive_menuitem(self):
635636
record.write({key: value})
636637
self.assertEqual(record[key], value)
637638

638-
util.update_record_from_xml(self.env.cr, xmlid, ensure_references=True)
639+
util.update_record_from_xml(self.env.cr, xmlid)
639640
if util.version_gte("16.0"):
640641
record.invalidate_recordset(["name"])
641642
else:
642643
record.invalidate_cache(["name"], record.ids)
643644
for key, value in data_before.items():
644645
self.assertEqual(record[key], value)
645646

647+
def test_upgrade_record_from_xml_ensure_references(self):
648+
def change(xmlid):
649+
cat = self.env.ref(xmlid)
650+
result = cat.name
651+
cat.write({"name": str(uuid.uuid4())})
652+
util.flush(cat)
653+
util.invalidate(cat)
654+
return result
655+
656+
if util.version_gte("saas~13.5"):
657+
xmlid_tree = [
658+
"base.module_category_accounting_localizations_account_charts",
659+
"base.module_category_accounting_localizations",
660+
"base.module_category_accounting",
661+
]
662+
else:
663+
xmlid_tree = [
664+
"base.module_category_localization_account_charts",
665+
"base.module_category_localization",
666+
]
667+
668+
old_names = [change(xmlid) for xmlid in xmlid_tree]
669+
670+
util.update_record_from_xml(self.env.cr, xmlid_tree[0], ensure_references=True)
671+
672+
for xmlid, expected in zip(xmlid_tree, old_names):
673+
cat = self.env.ref(xmlid)
674+
self.assertEqual(cat.name, expected)
675+
646676
def test_update_record_from_xml_template_tag(self):
647677
# reset all fields on a <template>
648678
template_xmlid = "base.contact_name"

0 commit comments

Comments
 (0)