简体   繁体   English

Odoo 10为POS添加按钮

[英]Odoo 10 add button to POS

I am trying to add a button to the POS screen. 我想在POS屏幕上添加一个按钮。 A lot of the information I have for this is related to Odoo 8 and this is probably why it is not working. 我有很多这方面的信息与Odoo 8有关,这可能就是为什么它没有用。 I installed the custom addon without any errors but I don't see the button. 我安装了自定义插件没有任何错误,但我没有看到按钮。 I don't get any errors when running the POS either. 运行POS时我也没有遇到任何错误。 In version 8 there is a widgets.js file which includes 在版本8中,有一个包含的widgets.js文件

module.PosWidget.include({
        build_widgets: function(){
      var self = this;
      this._super()

There is no widgets.js in version 10 and I am guessing this is where my problem is. 版本10中没有widgets.js,我猜这是我的问题所在。 Its just a guess I really dont know how to add a button to the POS. 它只是一个猜测我真的不知道如何添加一个按钮到POS。

Here is my pos_custom.js 这是我的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`)


            }
})

};

My /src/xml/pos_custom.xml 我的/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>

my /views/templates.xml 我的/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>

manifest .py 清单 .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,


}

For a concrete example on how can this be done, check addons/pos_discount/static/src/js/discount.js . 有关如何完成此操作的具体示例,请检查addons/pos_discount/static/src/js/discount.js You can see here that a button with the label Discount is added in one of the screens of Odoo POS. 您可以在此处看到在Odoo POS的其中一个屏幕中添加了标签为Discount的按钮。 Check the whole module since what is basically does is adding a button on the action buttons of the POS (attaching screenshot) 检查整个模块,因为基本上是在POS的操作按钮上添加一个按钮(附加屏幕截图)

在此输入图像描述

Also check the template on addons/pos_discount/static/src/xml/discount_templates.xml for the layout of the button. 还要检查addons/pos_discount/static/src/xml/discount_templates.xml上的模板,以获取按钮的布局。

To create a buttton in the pos interface you need to create three files. 要在pos接口中创建buttton,您需要创建三个文件。

  1. xml file. xml文件。

  2. js file js文件

  3. xml file for template 模板的xml文件

  4. xml file xml文件

    this file is used to call the js file. 此文件用于调用js文件。 Also you need to set the path of this xml file in the manifest like 'data': ['view/pos_update_view.xml'] The code of this xml file is shown below: 您还需要在清单中设置此xml文件的路径,如'data':['view / pos_update_view.xml']此xml文件的代码如下所示:

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

You only need to change the path of the js file which is in the src="YOUR JS FILE PATH" 您只需要更改src =“YOUR JS FILE PATH”中的js文件的路径

  1. js file js文件

    In normal situation the location of the js file will be in FOLDER_NAME/STATIC/SRC/JS/FILENAME.JS 在正常情况下,js文件的位置将在FOLDER_NAME / STATIC / SRC / JS / FILENAME.JS中

    odoo.define('clear_button_fun.pos_view',function(require){ "use strict"; odoo.define('clear_button_fun.pos_view',function(require){“use strict”;

    var screens = require('point_of_sale.screens'); var screens = require('point_of_sale.screens'); var gui = require('point_of_sale.gui'); var gui = require('point_of_sale.gui'); var core = require('web.core'); var core = require('web.core');

    var ClearCartLine = screens.ActionButtonWidget.extend({ template: "ClearCartLine", var ClearCartLine = screens.ActionButtonWidget.extend({template:“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,}); screens.define_action_button({'name':'clear_button_fun','widget':ClearCartLine,});

    }); });

    In the above code ClearCartLine is the template name and it must be same in all places. 在上面的代码中,ClearCartLine是模板名称,它在所有地方必须相同。 clear_button_fun() is the name of the function and you can add your code to tell what to do when clicking on that button. clear_button_fun()是函数的名称,您可以添加代码以告知单击该按钮时要执行的操作。

  2. xml file. xml文件。

    This xml file is to create a button as a template. 此xml文件用于创建按钮作为模板。 In normal situation the location of this xml file will be in FOLDER_NAME/STATIC/SRC/XML/FILENAME.XML 在正常情况下,此xml文件的位置将位于FOLDER_NAME / STATIC / SRC / XML / FILENAME.XML中

Also you need to set this template location in the manifest. 您还需要在清单中设置此模板位置。 Like 'qweb': ['static/src/xml/pos_view.xml'] 像'qweb':['static / src / xml / pos_view.xml']

<t t-name="ClearCartLine">
    <div class='control-button'>
        Clear Oder Line
    </div>
</t>

I hope the above description helps you. 我希望上面的描述可以帮到你。

Maybe you should change your codes 也许你应该改变你的代码

id="assets_backend" into id="assets" & id="assets_backend"进入id="assets"

inherit_id="web.assets_backend" into inherit_id="point_of_sale.assets" inherit_id="web.assets_backend" into inherit_id="point_of_sale.assets"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM