Hi,
You can get an age calculated automatically on selected the birth_date filed.
You have to write following code:
First import calender, you can override onchange method as follows:-
def _on_change_date_of_birth(self, cr, uid, ids, date_of_birth, ctx={}):
if date_of_birth:
birth_dt = dt.strptime(date_of_birth, '%Y-%m-%d')
b_yr = int(birth_dt.strftime('%Y'))
b_mnth = int(birth_dt.strftime('%m'))
b_dt = int(birth_dt.strftime('%d'))
birthday = Time(b_yr,b_mnth,b_dt)
today = Time(2010,02,10)
years, months, period = today.diffym(birthday)
return {'value':{'age':years}}
This will calculate the age of person. Now if you want to take current date
also dynamic than you can use the following code:
def _on_change_date_of_birth(self, cr, uid, ids, date_of_birth, ctx={}):
if date_of_birth:
birth_dt = dt.strptime(date_of_birth, '%Y-%m-%d')
b_yr = int(birth_dt.strftime('%Y'))
b_mnth = int(birth_dt.strftime('%m'))
b_dt = int(birth_dt.strftime('%d'))
birthday = Time(b_yr,b_mnth,b_dt)
current_date = datetime.datetime.now()
c_yr = int(current_date.strftime('%Y'))
c_mnth = int(current_date.strftime('%m'))
c_dt = int(current_date.strftime('%d'))
years, months, period = today.diffym(birthday)
return {'value':{'age':years}}
Thanks :)
Palvesha
------------------------
Palvesha Hakim
Software Engineer
-------------------- m2f --------------------
--
http://www.openobject.com/forum/viewtopic.php?p=50988#50988
-------------------- m2f --------------------
_______________________________________________
Tinyerp-users mailing list
http://tiny.be/mailman2/listinfo/tinyerp-users