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

Hello everybody!!!

Who can explain please how to make a computed field stored in database.

PS: This field should depend on any field.

Thaks a lot in advance.

Best Regards.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

drees you can make your field stored  in the database by store =True and update it via a function or a trigger because in odoo 10 when you make a field computed it ignore the store part i don't know why



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Just add store=True to the declaration of the field like in account.invoice : 

    amount_untaxed = fields.Monetary(string='Untaxed Amount',  store=True, readonly=True, compute='_compute_amount', track_visibility='always')

A computed field must depends on an other field (or more) to be computed see \https://github.com/odoo/odoo/issues/9946
อวตาร
ละทิ้ง
ผู้เขียน

Sorry but it doesnt work i have found nothing stored in the database :/

For old records I think you must update your module, you test it bay creating a new record?

ผู้เขียน

That is what i have done exactly. But, i havnt found anything in the database

ผู้เขียน

Hey friend in the example that you have put (account.invoice model) the field is depending from others thats why its stored in database

The field was created in the DB?

ผู้เขียน

yes but the value is not displayed even store

I check if you have no dependency just add a required field to trigger it, or just add it on create methode

I mean @depends on a required field or just define it as a normal field and compute it in the create or write methode if there is no dependency on other fields

ผู้เขียน

My field is calculaing the period from the create of the record till the date of the day. So that, it should be computed unless you have an other solution

So it depends on create_date you can add it as a field, unfortunately there no other solution, find this https://github.com/odoo/odoo/issues/9946

ผู้เขียน

I have told you that !!!! My field should be recomputed but the create-date will not change so that my method will not be called

If I understand your need you can achieve it by adding a button to trigger the calculation you can't do it automatically

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มี.ค. 24
1744
How can I recover ownership? แก้ไขแล้ว
1
ก.พ. 23
2012
Odoo database failed แก้ไขแล้ว
1
ธ.ค. 22
11593
0
ส.ค. 19
5362
4
ธ.ค. 18
23130