Odoo12升级14后muk_web_utils模块视图与JS报错修复咨询
Odoo 12升级到14 MuK Web Utils适配错误修复方案
错误1:视图验证无法定位<xpath expr="//script[last()]">节点
原因
Odoo 13及以上版本重构了web.qunit_suite视图的资源结构,原生模板中不再存在可匹配//script[last()]规则的节点,原有XPath定位逻辑失效。
修复步骤
- 打开
custom/muk_web_utils/template/assets.xml文件,找到继承web.qunit_suite的视图节点 - 将原有XPath表达式替换为适配Odoo 14的定位规则,通用规则如下:
<xpath expr="//div[@id='qunit_container']/preceding-sibling::script[last()]" position="after"> <!-- 原有插入的脚本节点保持不变 --> </xpath>
如果是插入测试资源,也可以直接定位到Odoo预留的测试脚本插入位:
<xpath expr="//script[contains(@src, '/web/tests/boot.js')]" position="after">
错误2:TypeError: view.getcontroller(...).then.guardedcatch is not a function
原因
Odoo 12中异步接口返回的是jQuery Deferred对象,框架额外扩展了guardedCatch等专属方法;Odoo 14已将绝大多数异步接口替换为返回标准原生Promise,原生Promise不存在guardedCatch方法,调用就会抛出该错误。
修复步骤
- 找到模块内所有QUnit测试JS代码中调用
guardedCatch的位置 - 将所有
.guardedCatch()替换为标准Promise的.catch()方法 - 同步检查其他jQuery Deferred专属API的调用,同步替换为标准Promise语法:
.done()替换为.then().fail()替换为.catch().always()替换为.finally()
内容的提问来源于stack exchange,提问作者deen
相关产品推荐
相关产品推荐

