javascript - Odoo - 从树头中的新按钮加载表单 View

标签 javascript python-2.7 odoo-10

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

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', [[]])

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

    @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 View 定义中定义的按钮在其他 View 中调用此方法作为测试时,它的行为符合预期。

最佳答案

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

其中 res 是 python 返回的值

关于javascript - Odoo - 从树头中的新按钮加载表单 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48694835/

相关文章:

Python Unicode 编码错误

Python 和换行符

python - CMD中的`python`返回"` python ` is not recognized ..."

java - Odoo REST API 是否允许登录 Odoo Web UI 后端?

odoo - 如何通过 odoo Web 客户端中的按钮单击调用服务器操作

javascript - 为什么node express中的mongodb无法将结果设置为外部变量

javascript - 使用 classList 隐藏和显示元素的问题

python - 保存后字段归零

javascript - 需要帮助根据元素的宽度定位元素 (Javascript)

javascript - 如何检测数组是否包含特定长度的值