简体   繁体   English

Odoo 12:在sale.order模型中单击“保存”按钮时如何弹出消息?

[英]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 ). 我想在满足条件(_some字段等于某事 )时显示弹出窗口( 非阻塞窗口),同时用户在sale.order模型的记录视图上单击“保存”按钮( )。
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. 我在这里找到如何从Odoo中的javascript获取model.Models。
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. 我还发现我需要重写o_form_button_edit进行更改,但是我不知道该怎么做,也不知道它是否对其他模型有效,因为其他人正在使用它。

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. PS:我需要一个弹出窗口,因为用户可以在保存记录时接受他的更改或放弃它。 If discard, I need to re-open o_form_button_edit if not, we do nothing because we already call the write method. 如果丢弃,我需要重新打开o_form_button_edit,否则,我们什么也不做,因为我们已经调用了write方法。

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. 您还需要以相同的方式继承createRecord()方法。

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) 第一个控制台日志行说:[“ name”]是changedFields的值(我只在点击保存之前更改了任务的名称)
  • I was working on the project.task object but you can change that to sale.order :) 我正在研究project.task对象,但您可以将其更改为sale.order :)

The official documentation is very helpful 官方文档非常有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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