I have defined a onchange and returned the calculated age from give date of birth(dob)
def onchange_getage_id(self, cr, uid, ids, dob, context=None):
if dob:
current_age = datetime.now().year - parser.parse(dob).year
print current_age
return {'value':{'age':current_age}}
else:
return {'value':{'age':' '}}
I have declared that age field has integer like this.
'age' : fields.integer('Age'),
While entering dob it returns the age, but when we remove and give nothing in field it return with
Error: [_.sprintf] expecting number but found string
I found the answer!
If you have declared the field has integer you must have to return the dictionary value has integer.
I have returned it has space (return {'value':{'age':' '}}
) that means string. This is the reason for error.
So did the following change in return value in else part.
else
return {'value':{'age':0}}