تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
7670 أدوات العرض

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
مارس 20
38409
2
ديسمبر 15
4436
1
مايو 25
644
0
يناير 24
1412
2
مايو 23
8251