Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
6155 Переглядів

Hi all,

I intend to make 

annual_dateofbirth=fields.Date('Nächster Geburtstag', compute='_calc_annual_dob',store=True)

available as Filter. I set stored=True to make it available as Field within Filter. However, it Needs to be recalculated on each page load. Thats why I introduced a second field current_date. 

current_date=fields.Date('Aktuelles Datum', compute='_calc_current_date')


@api.depends('current_date')
def _calc_current_date(self):
for rec in self:
rec.current_date = date.today()

@api.depends('current_date')
def _calc_annual_dob(self):
for rec in self:
if rec.birthday:
today = date.today()
dob = rec.birthday.replace(year=today.year)

if parsed < today:
dob= dob.replace(year=today.year + 1)

rec.annual_dateofbirth=parsed.strftime("%Y-%m-%d")


However, _calc_annual_dob is only executed when the field is changed in the form, not on page reload.

I appreciate any hint!

Regards,

Matthias


Аватар
Відмінити
Найкраща відповідь

Hi,

By default, a computed field is not stored in the database and is computed on-the-fly. Adding the attribute store=True will store the field’s values in the database. The advantage of a stored field is that searching on that field is done by the database itself. The disadvantage is that it requires database updates when the field must be recomputed.


Thanks

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
квіт. 24
1291
2
бер. 24
1871
2
лист. 19
6734
1
трав. 19
3757
2
квіт. 18
12473