如何在Odoo 18.0 POS的ControlButtons区域添加自定义按钮?
Odoo 18 POS产品屏幕添加自定义按钮失败排查
我在Ubuntu 24.04(WSL环境)运行Odoo 18.0,尝试在POS产品屏幕的ControlButtons区域(「Action」按钮旁)添加自定义按钮,试过多种方法,甚至完全照搬Odoo 18.0相关YouTube教程的代码,但始终未成功。
我已经能在crm.lead中创建自定义按钮,也能新建根菜单项、动作、列表及表单视图,但本次POS自定义按钮的代码完全未生效:浏览器控制台未输出CustomButton.js中的console.log内容,日志和控制台均无报错。
相关代码
manifest.py(部分代码)
'depends': ['point_of_sale'], 'assets': { 'point_of_sale.assets': [ 'button_pos/static/src/js/CustomButton.js', 'button_pos/static/src/xml/CustomButton.xml', ], },
CustomButton.js
/** @odoo-module **/ import { patch } from "@web/core/utils/patch"; import { ControlButtons } from "@point_of_sale/app/screens/product_screen/control_buttons/control_buttons"; console.log("CustomButton.js loaded"); patch(ControlButtons.prototype, { onClickCustomButton() { alert("Custom POS button clicked!"); }, });
注:我通过console.log检查浏览器是否加载该JS,但开发者工具控制台无输出,已确认manifest.py中的路径无误。
CustomButton.xml
<odoo> <data> <templates id="custom_pos_button_templates" xml:space="preserve"> <t t-name="custom_pos_button.ControlButtons" t-inherit="point_of_sale.ControlButtons" t-inherit-mode="extension" owl="1"> <xpath expr="//div[contains(@class, 'control-buttons')]" position="inside"> <button t-att-class="buttonClass" t-on-click="() => this.onClickCustomButton()"> Custom Button </button> </xpath> </t> </templates> </data> </odoo>
内容的提问来源于stack exchange,提问作者Shafin Ahmed
相关产品推荐
相关产品推荐

