This question has been flagged

I am somehow a newbie to Odoo. I would like to ask for a solution maybe a code could help.

I got a module that inherit age with calculation from date_of_birth(dob) to my Main_Custom_Module (store=true) with the below :



from dateutil.relativedelta import relativedelta

from odoo import api, fields, models


class BitsBits(models.Model):
    _inherit = "bits.bits"

    age = fields.Integer(string="Age"readonly=Truecompute="_compute_age")

    @api.depends("dob")
    def _compute_age(self):
        for record in self:
            age = 0
            if record.dob:
                age = relativedelta(fields.Date.today(), record.dob).years
            record.age = age

It's working perfectly.

Issue one: I have more than 50,000 record to upload to my main module. So i had to use pgadmin to do so. (All of records contains 'dob' date_of_birth field).


Question: How to make this field 'age' to be updated and calculated in Odoo when i upload data with 'dob' field directly to my databse ?

(cronjob maybe ?)  




Hope someone could cheer me up with this.

Thanks!

Avatar
Discard
Author

Thanks for anyone who watched and tried to figure out. But i made it.

    @api.model
    def _cron_update_compute_age(self):


and with Cronjob in Data folder to create a scheduled action.

Best Answer

COPYING THE COMMENT INTO THIS ANSWER SO THIS QUESTION CAN BE MARKED AS ANSWERED:


From Bilal Shehab - 30 July 2020:


Thanks for anyone who watched and tried to figure out. But i made it.

    @api.model
    def _cron_update_compute_age(self):


and with Cronjob in Data folder to create a scheduled action.

Avatar
Discard
Author

Oh ok, Thanks for doing that !