Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
7656 Visualizzazioni

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
Abbandona
Autore

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.

Autore Risposta migliore

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
Abbandona
Risposta migliore

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
Abbandona
Autore

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.

Post correlati Risposte Visualizzazioni Attività
4
mar 20
38373
2
dic 15
4426
1
mag 25
628
0
gen 24
1393
2
mag 23
8234