Skip to Content
Menu
This question has been flagged
2 Replies
7580 Views

Hi.

I need to have a field A that is recomputed when a field B is changed.

But also need that field B is recomputed when field A changes.

I tried using two @api.depends methods, dealing myself to avoid actual infinite changes. But Odoo just throws a recursion error making this way impossible.

In version 6.1 and 7.0 I used some ugly hacks like onchange methods and dummy boolean fields, or trying to use the context to set a flag to cut the changes (still fighting with it). And that's what I am trying now in v8, with @api.onchange, but that is an ugly hack anyway.

Another cleaner way to deal with this situation, please?

Avatar
Discard
Author

Finally I wil use @api.onchange + context. See the answer in https://www.odoo.com/forum/help-1/question/how-to-actually-use-and-modify-context-71903 , which solved the issue for me.

Author Best Answer

Also see my question about the usage/update of context: https://www.odoo.com/forum/help-1/question/how-to-actually-use-and-modify-context-71903

So far, in this situation (A may modify B, B may modify A):

  • @api.depends: impossible. Simply raises errors and Odoo server crashes.
  • @api.onchange + context: no way if I cannot update context.
  • @api.onchange + readonly boolean fields: It looks the only way, like in v6.1. But it is ugly, weird, hard to implement and completely sends to hell the promised new API "easiness".

There must be an easier way with API v8, isn't it? Sure I am just missing it... I hope.

Avatar
Discard
Best Answer

Yes you can use @api.depends( field A) and then define your method which compute value of field B. In @api.depends, onchange is default. That means whenever you change value of field A it will recompute value of field B. If you need more clarifications, Iet me know, I can help you.

Avatar
Discard
Author

Yes, using @api.depends one way works perfectly. So, when I change A, it computes B. Easy and fine. The problem arises it is a two-way situation: A modifies B, but also B modifies A. Then, what should I do? Odoo does not let me define crossed @api.depends on compute methods, giving a recursion error. I can use two @api.onchange functions, but I need to use either the context (which is giving me some trouble) or some readonly fields, which feels clumsy and ugly.

Related Posts Replies Views Activity
4
Mar 20
38244
2
Dec 15
4368
1
May 25
540
0
Jan 24
1284
2
May 23
8131