Skip to Content
Menu
This question has been flagged
1 Reply
2532 Views

Hi

Below an example to illustrate my issue.

I have two models, model B has a One2many link to model A.

On the model B view, I display the field 'link', and a button that calls function fct()

When the record is in edit mode, I would like the function fct() tu update the var1 field of the linked A record to be changed (without db commit). This does not works: the value is committed to db. 


class A(models.Model):
    var1 = fields.Char(...)
class B(models.Model):
    link = fields.One2many("A", ..)

    def fct(self):
        for r in self.link:
            r.var1 = "new value" # this is not working as expected

Could you please advice ?



Edit: after some tests, the changes are only not committed using @onchange, is there any solution to have the same behavior with buttons ?

Avatar
Discard
Author Best Answer

Hi

I have been testing previous solution tu use @api.multi:

    @api.multi
    def update_button(self):
        for record in self:
record.name = record.name + "x"
<button name="update_button" string="Update" type="object" />

This does not works, the field is changed & committed directly.

Avatar
Discard
Author

Note: this is a reply to user "Odoo Tools" that has now removed his comment....

yes, that is correct since my answer doesn't take into account the key word 'commit'.

In Odoo when you press the button, it firstly saves the object. So, using standard button it would be hardly possible to avoid committing. I guess, to your end you need to prepare your own js widget (as it is done for example for the button 'Add a line' in one2many widget). You can find examples of widgets in the 'web' module.

Related Posts Replies Views Activity
2
Sep 22
7887
2
Apr 22
2452
0
Jul 21
5314
1
Mar 21
3340
5
Aug 20
16281