I am creating a record using a button action that calls a create() method. But some computed fields are not being computed. I did some print statements in the compute function and they did not show in logs which means it is not being called. Is this normal behavior ?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- ลูกค้าสัมพันธ์
- e-Commerce
- ระบบบัญชี
- สินค้าคงคลัง
- PoS
- Project
- MRP
คำถามนี้ถูกตั้งค่าสถานะ
You need to add the dependent fields in @api.depends of the computed function so that it's called when the corresponding fields are modified on the create() function.
Also a dirty trick is to set store=False on your computed field which will ensure that the compute function is always called, at least on each record fetching.
this solution worked perfectly for me, @api.depends and store=False are both worked.
I see that compute works only for fields that is set on views(visible or not). Existing on view is the trigger compute function if not any @api.depends defined or store = False is set. I think this works like this because the value of computed field is needed to show to user. I realize that compute functions also works after create function works and record get it's ID unless computed field is called by another function before create function works. If you want to set value on create from code it is better to set default value with a lambda code.
Do you set the value of the dependent fields in your create()? If the dependent fields' values not set the computed function will not be triggered.
in reply to @Khalid Hazam , I already have @api.depends, the computed field is computed correctly when i create a record using the UI, the problem is when I call the create() from code
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อRelated Posts | ตอบกลับ | มุมมอง | กิจกรรม | |
---|---|---|---|---|
|
4
มี.ค. 25
|
7537 | ||
|
1
ก.พ. 21
|
3411 | ||
|
4
ต.ค. 20
|
8707 | ||
|
2
มิ.ย. 25
|
988 | ||
|
0
พ.ค. 25
|
12 |
compute fields wont be storing in the db, unless you haven't set store=True. Try opening corresponding view and see, whether the compute function is get called.
the field has store=True, and I am not creating the record from the view, i am creating it from python.
did you find the answer yet?