Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2209 Lượt xem

Hello,

here is my problem

In the project.task form, i added a one2many linked to a new model equipment.

How force the save of the project.task before i open the popup form of an equipment

The record is automatic when you click on a button but not on a record of a one2many

Hope it clear enough

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You want to force the save of the project.task before opening the popup form of an equipment in a one2many field. Here are a couple of ways you might achieve this:

  1. JavaScript: You can override the onchange method for the one2many field in JavaScript to force a save before opening the popup. This would require some knowledge of Odoo’s JavaScript framework.
  2. Python: You can override the write or create method in Python to save the project.task before opening the popup. This would require some knowledge of Odoo’s Python framework.

Here is a sample code snippet for the Python method:

@api.multi
def write(self, vals):
    res = super(ProjectTask, self).write(vals)
    # Add your logic here to open the popup
    return res

And here is a sample code snippet for the JavaScript method:

openerp.module_name = function (instance) {
    var _t = instance.web._t;
    instance.web.form.One2ManyDataSet.include({
        onchange: function (id, fieldname, value) {
            var self = this;
            return $.when(this._super.apply(this, arguments)).then(function () {
                // Add your logic here to open the popup
            });
        },
    });
};

Replace module_name with the name of your module. Also, please note that these are just sample code snippets and might need to be adjusted to fit your specific use case.  

Ảnh đại diện
Huỷ bỏ
Tác giả

Hi Maciej,
Thank you for you very complete answer but i don't understand the python part.
I use to override write method of a model.
But my problem is not to override write (or create) method but to trigger it when i click on a record of the one2many