odoo tree視圖頂部添加按鈕,點擊按鈕打開新的form

效果:點擊“請假申請”按鈕,跳轉到下面的form界面

按鈕添加參考這篇:https://blog.csdn.net/Katherine130/article/details/103457644

 

js文件代碼

odoo.define('bicon_wms_base.bicon_list_view_button', function (require) {
    "use strict";
    var ListView = require('web.ListView');
    var viewRegistry = require('web.view_registry');
    var ListController = require('web.ListController');
    var core = require('web.core');
    var _t = core._t;
    //這塊代碼是繼承ListController在原來的基礎上進⾏擴展
    var BiConListController = ListController.extend({
        renderButtons: function () {

            this._super.apply(this, arguments);
            if (this.$buttons) { 
                var leavebtn = this.$buttons.find('.leave_apply');
                leavebtn.on('click', this.proxy('show_leave_apply'));


            }


        },


        show_leave_apply: function () {
            var self = this;
//            console.log('create makeup apply!!!!!!');
            //rpc先去查view的id,得到的結果傳給then的方法,在then中打開視圖
            this._rpc({
                model: 'ir.model.data',
                method: 'get_object_reference',
        
                args: ['hr_attendance','leave_apply_form']
            }).then(function (view_ids) {
                self.do_action({
                res_model: 'hr.leave.apply',
                name: '申請',
                views: [[view_ids[1], 'form']],
                view_mode: 'form',
                target: 'current',
                type: 'ir.actions.act_window',
                context: {
                    'default_apply_type': 'leave'
                }
            });
            });
        },

    var BiConListView = ListView.extend({
        config: _.extend({}, ListView.prototype.config, {
            Controller: BiConListController,
        }),
    });
    //這來註冊編寫的視圖BiConListView,第⼀個字符串是註冊名到時候需要根據註冊名調⽤視圖
    viewRegistry.add('bicon_list_view_button', BiConListView);
    return BiConListView;
});

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章