I have an age calculation function (onchange) and it calculates and shows up in the form when I enter the data. But the data is not saved in the data base. Please help with the code.
@api.onchange('dob')
def onchange_age_calculate(self):
if not self.dob:
self.age = 0
else:
today_date = datetime.datetime.now().year
date_split = self.dob.split('-',1)
birth_year = date_split[0]
self.age = today_date -int(birth_year)
_columns = {
'name': fields.char(string="Name"),
'dob' : fields.date('Date of Birth'),
'age' : fields.float( string='Age')
I have imported date time and the required library files hope so
Reference: https://learnopenerp.blogspot.com/2021/10/onchange-method-readonly-field-not-store-database-odoo.html