Odoo 10 添加按钮到 POS

Odoo 10 add button to POS

我正在尝试向 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,


}

有关如何完成此操作的具体示例,请查看 addons/pos_discount/static/src/js/discount.js。您可以在这里看到在 Odoo POS 的其中一个屏幕中添加了一个带有标签 Discount 的按钮。检查整个模块,因为基本上是在 POS 的操作按钮上添加一个按钮(附上屏幕截图)

还要检查 addons/pos_discount/static/src/xml/discount_templates.xml 上的模板以了解按钮的布局。

也许你应该更改密码

id="assets_backend" 变成 id="assets" &

inherit_id="web.assets_backend" 变成 inherit_id="point_of_sale.assets"

要在 pos 界面中创建一个按钮,您需要创建三个文件。

  1. xml 文件.

  2. js文件

  3. xml 模板文件

  4. xml 文件

    这个文件是用来调用js文件的。您还需要在清单中设置此 xml 文件的路径,如 'data': ['view/pos_update_view.xml'] 这个xml文件的代码如下所示:

                <script type="text/javascript" src="/pos_update/static/src/js/cancel.js"></script>
    
            </xpath>
        </template>
    </data>
    

只需要修改src中js文件的路径即可="YOUR JS FILE PATH"

  1. js文件

    正常情况下js文件的位置会在FOLDER_NAME/STATIC/SRC/JS/FILENAME.JS

    odoo.define('clear_button_fun.pos_view',函数(要求){ "use strict";

    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() 是函数的名称,您可以添加代码以告知单击该按钮时要执行的操作。

  2. 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>

希望以上描述对您有所帮助