简体   繁体   English

如何继承 Odoo 的 POS 按钮

[英]How to inherit Odoo's POS buttons

I'm trying to add some functions in the POS buttons, specifically the button that shows up like "Validate".我正在尝试在 POS 按钮中添加一些功能,特别是显示为“验证”的按钮。 To test if the guide in this link https://odoo-development.readthedocs.io/en/latest/dev/pos/gui.html works, I'm just adding a console.log like the following:要测试此链接https://odoo-development.readthedocs.io/en/latest/dev/pos/gui.html中的指南是否有效,我只需添加一个如下所示的 console.log:

odoo.define('my_module.js_file', function (require) {
    "use strict";

    var screens = require('point_of_sale.screens');

    screens.PaymentScreenWidget.include({
    init: function(parent, options) {
        this._super(parent, options);
        //My console log message
        console.log('Hello world!')
        this.pos.on('updateDebtHistory', function(partner_ids){
            this.update_debt_history(partner_ids);
      }, this);
    },
  });

But the message only shows up once when the POS ends loading the data and not when I push the button.但是该消息仅在 POS 结束加载数据时显示一次,而不是在我按下按钮时显示。 What am I doing wrong here?我在这里做错了什么?

To add your code to the Validate button you will need to modify the payment screen widget via the include method ( You already did that ).要将您的代码添加到Validate按钮,您需要通过include方法修改支付屏幕小部件(您已经这样做了)。

If you inspect the button from the browser you will find that it has a class next which is used to bind an event handler to the click JavaScript event.如果您从浏览器中检查该按钮,您会发现它有一个 class next用于将事件处理程序绑定到单击JavaScript 事件。

Example :示例

var screens = require('point_of_sale.screens');
var PaymentScreenWidget = screens.PaymentScreenWidget;

PaymentScreenWidget.include({

    validate_order: function(force_validation) {
        console.log('Hello world!');
        this._super(force_validation);
    },

});

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

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