Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2889 มุมมอง

Hi all!

I'm beginner!

Assumption, I have a customize field 'd1_analytic_required' (boolean) in model 'account.invoice'
And, a customize field 'd1_analytic' (boolean) in model 'account.account'

I want to check on Vendor Bill, if account field (in line) have attribute d1_analytic = True then 'd1_analytic_required' = True. My code:

@api.onchange('account_id')
def _onchange_account_id(self):
for rec in self:
if rec.invoice_line_ids:
  sum1 = 0
for line in rec.invoice_line_ids:
if line.account_id.d1_analytic:
  sum1 += 1
if sum1 > 0:
  rec.d1_analytic_required = True
else
:
  rec.d1_analytic_required = False

It's not working!!
Please help me! Thank in advance!
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Instead of using the onchange API, I think you should use a computed_field.

In the case of onchange api, the "_onchange_account_id" function will be call only if you select a other account (not when you modify the line of the account).

With the computed_field, the "d1_analytic_required" will be set everytime you open the record (with a view or with orm)


อวตาร
ละทิ้ง
ผู้เขียน

Thank for your advice!

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ธ.ค. 24
1266
1
ต.ค. 23
2020
"Wrong value for %s: %r" % (self, value) แก้ไขแล้ว
2
ต.ค. 23
2245
First time Odoo user แก้ไขแล้ว
1
มี.ค. 24
4335
0
ก.ย. 23
1867