Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to deal with @api.depends recursion in v8?

By
Alejandro Santana
on 12/30/14, 6:16 PM 1,466 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?

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.

Anubía, soluciones en la nube, S.L., Alejandro Santana
on 1/5/15, 1:57 PM
0

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 12/30/14, 11:08 PM

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.

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.

Anubía, soluciones en la nube, S.L., Alejandro Santana
on 12/31/14, 3:02 AM
0
Alejandro Santana
On 12/30/14, 7:07 PM

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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/30/14, 6:16 PM
Seen: 1466 times
Last updated: 3/16/15, 8:10 AM