odoo 11的列表视图按钮上的调用操作(功能)

时间:2019-07-11 09:21:36

标签: javascript listview odoo odoo-11

我在创建和导入按钮附近的列表视图上添加了一个按钮。现在,我想对该按钮应用操作,但函数不调用该按钮。该按钮在列表视图上可见,并且文件名为我测试过的警报。第一个警报运行正常,但ListView.include警报不起作用。

我的js和XML代码在这里:

<?xml version="1.0" encoding="UTF-8"?>
<templates>
    <t t-extend="ListView.buttons" id="template" xml:space="preserve">
        <t t-jquery="button.o_list_button_add" t-operation="after">
            <button t-if="widget.model != 'account.analytic.line'" class="btn btn-primary btn-sm sync_button"
                    type="button" >HELP
            </button>
        </t>
    </t>
</templates>

Js文件:

odoo.define('custom_project.web_export_view', function (require){
"use strict";
var core = require('web.core');
var ListView = require('web.ListView');
var QWeb = core.qweb;
alert('Help1');
console.log('testtt',ListView.include)
ListView.include({
        render_buttons: function($node) {
                alert('Help2');
                var self = this;
                this._super($node);
                    this.$buttons.find('.o_list_tender_button_create').click(this.proxy('tree_view_action'));
        },

        tree_view_action: function () {
        alert('Help2');
        this.do_action({
                type: "ir.actions.act_window",
                name: "product",
                res_model: "product.template",
                views: [[false,'form']],
                target: 'current',
                view_type : 'form',
                view_mode : 'form',
                flags: {'form': {'action_buttons': true, 'options': {'mode': 'edit'}}}
        });
        return { 'type': 'ir.actions.client','tag': 'reload', } }

});
});

还附上截图以供理解。

list view button

有人可以为这个问题提出解决方案吗?

预先感谢

1 个答案:

答案 0 :(得分:1)

您可以这样写吗?

XML:

<?xml version="1.0" encoding="UTF-8"?>
<templates id="help_btn_template" xml:space="preserve">
<t t-extend="ListView.buttons" id="template" xml:space="preserve">
    <t t-jquery="button.o_list_button_add" t-operation="after">
        <button t-if="widget.model != 'account.analytic.line'" class="btn btn-primary btn-sm sync_button o_button_help"
                type="button" >HELP
        </button>
    </t>
</t>

JS:

odoo.define('custom_project.web_export_view', function (require) {

"use strict";       
var core = require('web.core');
var ListView = require('web.ListView'); 
var ListController = require("web.ListController");

var includeDict = {
    renderButtons: function () {
        this._super.apply(this, arguments);
        if (this.modelName === "account.analytic.line") {
            var your_btn = this.$buttons.find('button.o_button_help')                
            your_btn.on('click', this.proxy('o_button_help'))
        }
    },
    o_button_help: function(){
        var self = this;
        var state = self.model.get(self.handle, {raw: true});
        return self.do_action({
            name: 'product',
            type: 'ir.actions.act_window',
            res_model: 'product.template', #This model must Transient Model
            target: 'new',
            views: [[false, 'form']], 
            view_type : 'form',
            view_mode : 'form',
            flags: {'form': {'action_buttons': true, 'options': {'mode': 'edit'}}
        });
    }
};
ListController.include(includeDict);                
}); 

我希望这会对您有所帮助。谢谢。