简体   繁体   中英

Odoo 12 : How to pop up a message when “Save” button is clicked on sale.order model?


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 first console log line saying: ["name"] is the value of changedFields (I only changed the name of the task before hitting Save)
  • I was working on the project.task object but you can change that to sale.order :)

The official documentation is very helpful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM