Doubts about on change with


(Javier Uribe) #1

Hello, I have a doubt related to the on_change_with concepts. I have noticed on core_modules that sometimes depends have “parent_” and I believe that it has to do with the willing of its attribute triggers the method. So for example, if we put depends(‘inventory’, ‘_parent_inventory.state’), the fact that inventory’s state changed would trigger the on_change_with. If this were true, I have tried a lot of times and it doesn’t work and I would like to know if there is some way to link the changes of an attribute that belongs to another object, that is, If an object.attribute changes I want to trigger my method.

Thank you.


(Nicolas Évrard) #2

That’s indeed how it works.
How are you testing this because it should work.


(Javier Uribe) #3

Usually it is a ObjectLine that needs to change because of the many2One object, for instance, the state. So if we have a contract and contractLine, I want a on_change_with_stateLine that triggers when contract’s state changes.
By the way, I also had doubts if this whole _parent thing on depends were what I thought, because I have also saw this on on_change methods on the core, and that does not make sense then because on_changes are not like on_change_withs, the on_change depends are not made to trigger, they are only because we want to receive them from the client.


(Nicolas Évrard) #4

So it should work.

But if you want that the value of a field is always computed when the value of another field is changed (through an action of the user or some other process) then you should use a function field. Because on_changes are triggered by the client.


(Javier Uribe) #5

Yes, I always use the on_change_with as a getter for the function field. I think I have to insert it on the tree, I’ll use invisible attribute then, I think that’s why it hasn’t been working. Thank you for your help.