Odoo - 从树头中的新按钮加载表单视图

Odoo - load a form view from new button in tree header

我在 JS 中创建了两个新按钮并替换了模型树视图中的原始添加按钮:

ListView.include({
        render_buttons: function() {
            var self = this;            
            this._super.apply(this, arguments)
            if (this.model=='account.cash'){
            if (this.$buttons) {
                this.$buttons.find('.o_list_button_income').on('click', this.proxy('do_new_income'))
                this.$buttons.find('.o_list_button_add').css({"display":"none"})
            }
            }
        },   

        do_new_income: function () {

            var model = new Model('account.cash');
            var self = this;        
            model.call('new_income', [[]])

使用此按钮,我尝试通过以下方法调用表单视图:

    @api.model
    def new_income(self):
        view_id = self.env.ref('account.view_cash_statement_form').id
        context = self._context.copy()
        return {
            'name': 'New income',
            'view_type': 'form',
            'view_mode': 'form',
            'views': [(view_id, 'form')],
            'res_model': 'account.cash',
            'context': context,
            'target': 'current',
            'type': 'ir.actions.act_window'
        } 

但是这不起作用。当我尝试从标准 XML 视图定义中定义的按钮在其他视图中调用此方法作为测试时,它的行为符合预期。

model.call('new_income', [[]]).then(function (res) { self.do_action(res)})

其中 res 是 python 的返回值 成功了