![](/img/trans.png)
[英]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.