Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Odoo 10-将上下文传递给FormView.buttons模板内的按钮调用的向导_Javascript_Openerp - Fatal编程技术网

Javascript Odoo 10-将上下文传递给FormView.buttons模板内的按钮调用的向导

Javascript Odoo 10-将上下文传递给FormView.buttons模板内的按钮调用的向导,javascript,openerp,Javascript,Openerp,我在FormView中的创建按钮旁边添加了一个新按钮 <t t-extend="FormView.buttons"> <t t-jquery="button.o_form_button_create" t-operation="after"> <t t-if="widget.fields_view.name == 'site.form'"> <button type="button"

我在FormView中的创建按钮旁边添加了一个新按钮

<t t-extend="FormView.buttons">
    <t t-jquery="button.o_form_button_create" t-operation="after">
        <t t-if="widget.fields_view.name == 'site.form'">
            <button type="button"
                    class="btn btn-primary btn-sm oe_create_customer_button_form">
                Create Customer Site
            </button>
        </t>
    </t>
</t>
[已解决]

我重写了“load_record”函数以获取“datarecord”对象,并使用它代替“dataset”

代码如下:

instance.web.FormView.include({
    is_site: function() {
        if (this.dataset.model && this.dataset.model == 'broadband.site') {
            return true
        } else {
            return false
        }
    },
    render_buttons: function() {
        if(this.is_site() && !this.$buttons) {
            this._super.apply(this, arguments)
        }
    },
    load_record: function() {
        var self = this

        if(this.is_site()) {
            self._super.apply(this, arguments)
            var btn = self.$buttons.find('.oe_create_customer_button_form')
            btn.hide()
            if(self.datarecord.site_type != 'last_mile') {
                btn.show()
            }
            self.do_query(btn)
        } else {
            self._super.apply(this, arguments)
        }
    },
    do_query: function(btn) {
        var self = this
        var context = {}
        var passed = false

        if(this.is_site()) {

            var site_id = self.datarecord.id

            btn.on('click', function() {
                new instance.web.Model('broadband.site')
                    .query()
                    .filter([['id', '=', site_id]])
                    .first()
                    .then(function(res) {
                        if(res && !passed) {
                            context = {
                                'default_parent_id': res.id
                            }
                            self.do_button_action(context)
                            passed = true
                        }
                    })
            })
        }
    },
    do_button_action: function (context) {
        var self = this

        var action = ({
            type: 'ir.actions.act_window',
            res_model: 'broadband.wizard',
            view_type: 'form',
            view_mode: 'form',
            views: [[false, 'form']],
            target: 'new',
            context: context
        })

        self.do_action(action)

    }
})
instance.web.FormView.include({
    is_site: function() {
        if (this.dataset.model && this.dataset.model == 'broadband.site') {
            return true
        } else {
            return false
        }
    },
    render_buttons: function() {
        if(this.is_site() && !this.$buttons) {
            this._super.apply(this, arguments)
        }
    },
    load_record: function() {
        var self = this

        if(this.is_site()) {
            self._super.apply(this, arguments)
            var btn = self.$buttons.find('.oe_create_customer_button_form')
            btn.hide()
            if(self.datarecord.site_type != 'last_mile') {
                btn.show()
            }
            self.do_query(btn)
        } else {
            self._super.apply(this, arguments)
        }
    },
    do_query: function(btn) {
        var self = this
        var context = {}
        var passed = false

        if(this.is_site()) {

            var site_id = self.datarecord.id

            btn.on('click', function() {
                new instance.web.Model('broadband.site')
                    .query()
                    .filter([['id', '=', site_id]])
                    .first()
                    .then(function(res) {
                        if(res && !passed) {
                            context = {
                                'default_parent_id': res.id
                            }
                            self.do_button_action(context)
                            passed = true
                        }
                    })
            })
        }
    },
    do_button_action: function (context) {
        var self = this

        var action = ({
            type: 'ir.actions.act_window',
            res_model: 'broadband.wizard',
            view_type: 'form',
            view_mode: 'form',
            views: [[false, 'form']],
            target: 'new',
            context: context
        })

        self.do_action(action)

    }
})