odoo 10 - "Overwriting" Javascript 来自旧模块的代码

odoo 10 - "Overwriting" Javascript Code from old module

我正在尝试对新模块中的一些 javascript 进行更改,但我终究无法理解我做错了什么。

https://github.com/odoo/odoo/blob/10.0/addons/hr_attendance/static/src/js/kiosk_confirm.js

这是我要更改的代码,特别是这个片段:

this.next_action = 'hr_attendance.hr_attendance_action_kiosk_mode';

这是我到目前为止得到的代码,我认为这是最接近正确代码的迭代:

odoo.define('tko_hr_attendance.script', function(require) {
"use strict";

var core = require('web.core');
var Model = require('web.Model');
var Widget = require('web.Widget');

var QWeb = core.qweb;
var _t = core._t;


instance.web.WebClient.include({


    init: function (parent, action) {
        this._super.apply(this, arguments);
        this.next_action = 'mail.mail_channel_action_client_chat';
        return this._super();
        },
    });
});

这是我的 xml:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <template id="assets_backend_custom_id" name="tko_hr_attendance assets" inherit_id="web.assets_backend">
        <xpath expr="." position="inside">
            <script type="text/javascript" src="/tko_hr_attendance/static/src/js/script.js"></script>
        </xpath>
    </template>
</odoo>

我已经尝试遵循 odoo 8、9 和 10 中的示例,但我认为它们不适用于我尝试进行的特定更改,或者我不完全了解这些更改是如何进行的应用。

要覆盖 init 首先你需要得到 class 并且你在最后的代码中看到他们放在这里

   core.action_registry.add('hr_attendance_kiosk_confirm', KioskConfirm);

他们将其添加到 action_registry 您应该使用相同的密钥。

            var  KioskConfirm = core.action_registry.get('hr_attendance_kiosk_confirm');

然后使用 include 覆盖 init 方法,但在大多数情况下您应该始终调用 super。

       KioskConfirm.include({
                       init : function (){
                              this._super.applay(this, arguments)
                               //.your code here 
                      }
         });

要理解javascript 好好读读odoo教程构建扩展界面一天后你会很清楚如何去做