[英]Load custom model and add a field to pos.order.line in Point of Sale - Odoo 12
[英]Odoo 12 : How to pop up a message when “Save” button is clicked on sale.order model?
我被困了三个小时。
我想在满足条件(_some字段等于某事 )时显示弹出窗口( 非阻塞窗口),同时用户在sale.order模型的记录视图上单击“保存”按钮( 仅 )。
在“保存”按钮执行了其默认操作之后,应该触发弹出窗口,因为我需要检查数据库中是否满足该条件。
我在这里找到如何从Odoo中的javascript获取model.Models。
我还发现我需要重写o_form_button_edit进行更改,但是我不知道该怎么做,也不知道它是否对其他模型有效,因为其他人正在使用它。
this.$buttons.on('click', '.o_form_button_edit', this._onEdit.bind(this));
我想知道我的方法是否行得通? 如果不能,您可以建议另一个吗? 你能帮助我吗? 非常感谢你。
PS:我需要一个弹出窗口,因为用户可以在保存记录时接受他的更改或放弃它。 如果丢弃,我需要重新打开o_form_button_edit,否则,我们什么也不做,因为我们已经调用了write方法。
这是您需要执行的代码片段:
var FormController = require('web.FormController');
var ExtendFormController = FormController.include({
saveRecord: function () {
var res = this._super.apply(this, arguments);
if(this.modelName == 'project.task'){
var self = this;
res.then(function(changedFields){
console.log(changedFields);
console.log(self.modelName);
self.do_notify('title', 'message');
// you can call a method on the server like this
self._rpc({
model: self.modelName,
method: 'search_read',
fields: ['name'],
context: self.context,
}).then(function(result){
console.log('rpc result');
console.log(result);
})
});
}
return res;
}
});
您还需要以相同的方式继承createRecord()方法。
一些注意事项:
官方文档非常有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.