コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
7655 ビュー

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.

著作者 最善の回答

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.

アバター
破棄
最善の回答

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.

関連投稿 返信 ビュー 活動
4
3月 20
38372
2
12月 15
4426
1
5月 25
628
0
1月 24
1393
2
5月 23
8234