It has been 3 hours that I'm stuck.
I want to show up a pop up (a non-blocking one) when my condition is meet (_some field is equal something) while the user click the button "Save"on form view of record on sale.order model (only).
The pop up should be triggered after the Save button peformed its default action because I need to check if the condition is meet in database.
I find here how to get a model.Models from javascript in Odoo.
I also find that I need to override the o_form_button_edit to make my change, but I don't know how to do that and I don't know if it has effect to other model because others use it.
this.$buttons.on('click', '.o_form_button_edit', this._onEdit.bind(this));
I wonder if my method is good to do that? If not can you suggest another one?
Can you help me? Thank you very much.
PS : I need a pop up because the user can Accept his change or Discard it when saving the record. If discard, I need to re-open o_form_button_edit if not, we do nothing because we already call the write method.
Here is a code snippet doing what you want:
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;
}
});
A screenshot just after I clicked Save:
You also need to inherit the createRecord() method the same way.
A few notes:
The official documentation is very helpful