Javascript Odoo 10-将上下文传递给FormView.buttons模板内的按钮调用的向导
我在FormView中的创建按钮旁边添加了一个新按钮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"
<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)
}
})