Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
9473 Näkymät

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
Hylkää
Tekijä

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.

Paras vastaus

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
Hylkää
Tekijä

Oh ok, Thanks for doing that !

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
0
marrask. 24
50
1
heinäk. 25
5758
1
jouluk. 21
5099
1
heinäk. 21
3670
1
elok. 20
13693