I have three fields 'start_date', 'end_date' and total_days.
If i enter 'start_date' and 'end_date' field it should automatically display total_days.
This is my Function which is not working.
Is there any other method? or what may be the issue
<field name="start_date" on_change="get_number_of_days(start_date,end_date)"/>
<field name="end_date" on_change="get_number_of_days(end_date,start_date)"/>
<field name="total_days" />
def get_number_of_days(self, cr, uid, ids, start_date, end_date):
"""Returns a float equals to the timedelta between two dates given as string."""
result = self.browse(cr, uid, ids)
if (end_date and start_date) and (start_date <= end_date):
DATETIME_FORMAT = "%d/%m/%Y %H:%M:%S"
from_dt = datetime.datetime.strptime(start_date, DATETIME_FORMAT)
to_dt = datetime.datetime.strptime(end_date, DATETIME_FORMAT)
timedelta = to_dt - from_dt
diff_day = timedelta.days + float(timedelta.seconds) / 86400
result['value']['total_days'] = round(math.floor(diff_day))+1
return result