İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
6758 Görünümler

I have two fields such as date_of_birth and age.

date_of_birth = fields.Date(string='Date of Birth')
age = fields.Char(string='Age', compute='_compute_age')

@api.depends('date_of_birth') def _compute_age(self):
    for rec in self:
        dt = rec.date_of_birth
        d2 = date.today()
        d1 = datetime.strptime(dt, "%Y-%m-%d").date()
        rd = relativedelta(d2, d1)
        rec.age = str(rd.years) + ' years ' + str(rd.months) + ' months ' + str(rd.days) + ' days'

I want to auto compute to update the age field every day. How do I do that? 

Thanks in advance

Avatar
Vazgeç
En İyi Yanıt

Hi,

please check the codes of this module it will help you.

V11, V10

https://www.odoo.com/apps/modules/11.0/bi_birthday_reminder/

OR

V10

https://apps.odoo.com/apps/modules/10.0/birth_day_notification/

"Compute" function will run only when loading the tree view or form view.

To calculate the age in every day need to run a scheduler. This module will help you to create the scheduled cron job for the email notification. you change this and run the calculation function.

Nikhilkrishnan

Thank you

Avatar
Vazgeç
Üretici

Thank you :)

You said, `"Compute" function will run only when loading the tree view or form view.`

In my case, the compute method doesn't trigger when the form view or tree view is open up, I don't know why but it should trigger as far as I know. It only triggers when the server is restarted and the views are loaded.

Would you please explain what did you mean by loading?

please check that the compute field is defined in the tree view and the form.

in xml view please add the view for age and date_of_birth fields. then try again, the compute function automatically trigger.

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Ağu 23
16229
2
Şub 24
15678
1
Ara 22
5103
2
Ara 22
14604
2
Haz 22
6503