我在 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/