hi all i have added 2 fields in my odoo hr module , while updating the DOB it should return me the age in age filed but its not retuning someone help me with this , iam using odoo13
hr.py:
import base64
from random import choice
from string import digits
import itertools
from werkzeug import url_encode
import pytz
from datetime import datetime
import datetime
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError, AccessError
from odoo.modules.module import get_module_resource
from odoo.addons.resource.models.resource_mixin import timezone_datetime
from datetime import *
from datetime import date
from datetime import datetime
from dateutil.relativedelta import relativedelta
birthday = fields.Date(string="DOB")
age = fields.Integer(string="Age")
@api.onchange('birthday')
def _onchange_birth_date(self):
"""Updates age field when birth_date is changed"""
if self.birthday:
d1 = self.birthday
d2 = date.today()
self.age = relativedelta(d2, d1).years