Calculate total days from two dates

By
supreeth
on 12/16/15, 2:21 AM 842 views

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 `

Deepak Krishna
On 12/16/15, 4:33 AM

@deepak Thanks it worked

supreeth
on 12/16/15, 5:30 AM

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

1 follower(s)

Stats

 Asked: 12/16/15, 2:21 AM Seen: 842 times Last updated: 12/16/15, 4:33 AM