我正在尝试在POS屏幕上添加一个按钮。我有很多这方面的信息与Odoo 8有关,这可能就是为什么它没有用。我安装了自定义插件没有任何错误,但我没有看到按钮。我也不会在运行POS时遇到任何错误。在版本8中,有一个widgets.js文件,其中包含
module.PosWidget.include({
build_widgets: function(){
var self = this;
this._super()
版本10中没有widgets.js,我猜这是我的问题所在。这只是猜测我真的不知道如何在POS上添加一个按钮。
这是我的pos_custom.js
odoo.pos_custom = function(instance){
var module = instance.point_of_sale;
var round_pr = instance.web.round_precision
var QWeb = instance.web.qweb;
console.log("POS JS Loaded")
module.PosWidget.include({
build_widgets: function(){
var self = this;
this._super()
custom_btn = $(QWeb.render(`custom_btn`))
custom_btn.click(function(){
alert("hello")
})
console.log("button <<<>>> ",custom_btn,this.$(`.control-button`))
custom_btn.appendTo(this.$(`.control-button`))
this.$control_buttons`).removeClass(`oe_hidden`)
}
})
};
我的/src/xml/pos_custom.xml
<?xml version="1.0" encoding="UTF-8"?>
<templates xml="template" xml:space="preserve">
<t t-name="custom_btn">
<button>Cust Button</button>
</t>
</templates>
我的/views/templates.xml
<?xml version="1.0"?>
<openerp>
<data>
<template id="assets_backend" name="pos_custom assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_custom/static/src/js/pos_custom.js"></script>
</xpath>
</template>
</data>
</openerp>
清单的.py
{
'name': 'Point Custom Module',
'version': '1.2',
'category': 'Point of Sale',
'summary': 'Custom Point of Sale ',
'description': "",
'data': [
"views/templates.xml"
],
'depends': ['point_of_sale'],
'qweb': ['static/src/xml/*.xml'],
'application': True,
}
答案 0 :(得分:1)
有关如何完成此操作的具体示例,请检查addons/pos_discount/static/src/js/discount.js
。您可以在此处看到在Odoo POS的其中一个屏幕中添加了标签为Discount
的按钮。检查整个模块,因为基本上是在POS的操作按钮上添加一个按钮(附加屏幕截图)
同时检查addons/pos_discount/static/src/xml/discount_templates.xml
上的模板以了解按钮的布局。
答案 1 :(得分:0)
也许你应该改变你的代码
id="assets_backend"
加入id="assets"
&amp;
inherit_id="web.assets_backend"
加入inherit_id="point_of_sale.assets"
答案 2 :(得分:0)
要在pos界面中创建按钮,您需要创建三个文件。
xml文件。
js文件
模板的xml文件
xml文件
此文件用于调用js文件。另外,您需要在清单中像“数据”一样设置此xml文件的路径:['view / pos_update_view.xml'] 此xml文件的代码如下所示:
<script type="text/javascript" src="/pos_update/static/src/js/cancel.js"></script>
</xpath>
</template>
</data>
您只需要更改src =“您的JS文件路径”中的js文件的路径
js文件
通常情况下,js文件的位置位于FOLDER_NAME / STATIC / SRC / JS / FILENAME.JS
odoo.define('clear_button_fun.pos_view',function(require){ “使用严格”;
var screens = require('point_of_sale.screens'); var gui = require('point_of_sale.gui'); var core = require('web.core');
var ClearCartLine = screens.ActionButtonWidget.extend({ 模板:“ ClearCartLine”,
button_click: function(){
var self = this;
this.clear_button_fun();
},
clear_button_fun(){
var order = this.pos.get_order();
order.remove_orderline(order.get_selected_orderline())
},
}); screens.define_action_button({'name':'clear_button_fun','widget':ClearCartLine,});
});
在上面的代码中,ClearCartLine是模板名称,并且在所有地方都必须相同。 clear_button_fun()是函数的名称,您可以添加代码以告诉您单击该按钮时的操作。
xml文件。
此xml文件将创建一个按钮作为模板。在正常情况下,此xml文件的位置位于FOLDER_NAME / STATIC / SRC / XML / FILENAME.XML
此外,您需要在清单中设置此模板位置。就像“ qweb”一样:['static / src / xml / pos_view.xml']
<t t-name="ClearCartLine">
<div class='control-button'>
Clear Oder Line
</div>
</t>
希望以上描述对您有所帮助。