Odoo12继承模块在POS结账区添加按钮不显示求助
Odoo12 POS结账区添加按钮不显示问题排查
尝试通过继承模块在Odoo12的POS结账(PaymentScreen)区域添加按钮,但按钮始终无法显示,以下是相关代码:
custom_buttom_payment.js
odoo.define('pos_custom_button_payment.custom_button_payment', function (require) { "use strict"; var screen = require('point_of_sale.screens'); screen.PaymentScreenWidget.include({ renderElement: function() { var self = this; this._super(); this.$('.js_clear_orderline').click(function(){ }); }, }); });
button_custom.xml
<?xml version="1.0" encoding="utf-8"?> <templates id="template" xml:space="preserve"> <t t-extend="PaymentScreenWidget"> <t t-jquery="div[class*='js_set_customer']" t-operation="after"> <div class='left_button js_clear_orderline'> <div class="button-icon"> <img src="/pos_custom_button_payment/static/src/icons/icon.png" class="pos_logo"/> </div> <div class='button-name'> HELLO </div> </div> </t> </t> </templates>
view.xml
<?xml version="1.0" encoding="utf-8"?> <odoo> <data> <template id="pos_custom_button" inherit_id="point_of_sale.assets"> <xpath expr="." position="inside"> <script type="text/javascript" src="/pos_custom_button_payment/static/src/js/custom_button_payment.js"/> </xpath> </template> </data> </odoo>
排查方向及解决方法
- 模板未声明加载:检查模块
__manifest__.py的data列表,确认button_custom.xml已被添加,Odoo不会自动加载未声明的模板文件。示例:'data': [ 'views/view.xml', 'views/button_custom.xml', ], - jQuery选择器不匹配:打开POS页面开发者工具,检查结账区DOM结构,确认
div[class*='js_set_customer']元素是否存在。若选择器失效,可改用更可靠的容器选择器,比如.payment-buttons .left-buttons。 - 静态资源路径错误:验证图标文件路径是否正确,可先移除图片标签,仅保留文字按钮测试是否显示。
- 模块依赖缺失:确认
__manifest__.py中已声明depends: ['point_of_sale'],确保模块依赖加载顺序正确。 - 缓存未清理:更新模块后,清除Odoo服务器缓存、浏览器缓存,重启服务并刷新POS页面(可开启开发者工具禁用缓存选项)。
内容的提问来源于stack exchange,提问作者Huy Trần
相关产品推荐
相关产品推荐

