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

In my model, there is a compute field A, it is computed from 2 number fields B and C and 1 checkbox field D. My wanted compute code is like below:

 

Dependencies: B, C, D


Code:


for record in self:

    if record.D == True:

        record['A'] = record.B + record.C

    else:

        record['A'] = record.B

 

How do I write "if record.D == True" correctly? It doesn’t work now.

 

Thanks


الصورة الرمزية
إهمال
أفضل إجابة

This should work:

A = fields.Integer(compute="_compute_A")

@api.depends("B","C","D")
def _compute_A(self):
​for record in self:
​if record.D:
​record.A = record.B + record.C
​else:
record.a = record.B​

الصورة الرمزية
إهمال
الكاتب

Hi, I know what happens now. When I click D, I have to click the 'Save manually' button for A to update.

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يونيو 25
15362
3
أبريل 25
5528
Compute Fields تم الحل
2
يوليو 24
2513
1
يناير 24
1808
2
ديسمبر 23
1434