From 533434e878004862d14ec4289dcfbbba0272ffe5 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 14 Jul 2015 10:39:33 +0530 Subject: [PATCH] [fix] overlap fix in time log #3647 --- erpnext/projects/doctype/time_log/time_log.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/erpnext/projects/doctype/time_log/time_log.py b/erpnext/projects/doctype/time_log/time_log.py index 841ef28e16..ce87bd6085 100644 --- a/erpnext/projects/doctype/time_log/time_log.py +++ b/erpnext/projects/doctype/time_log/time_log.py @@ -73,18 +73,19 @@ class TimeLog(Document): def validate_overlap_for(self, fieldname): existing = self.get_overlap_for(fieldname) if existing: - frappe.throw(_("This Time Log conflicts with {0} for {1}").format(existing.name, - self.meta.get_label(fieldname)), OverlapError) + frappe.throw(_("This Time Log conflicts with {0} for {1} {2}").format(existing.name, + self.meta.get_label(fieldname), self.get(fieldname)), OverlapError) def get_overlap_for(self, fieldname): if not self.get(fieldname): return - existing = frappe.db.sql("""select name, from_time, to_time from `tabTime Log` where `{0}`=%(val)s and + existing = frappe.db.sql("""select name, from_time, to_time from `tabTime Log` + where `{0}`=%(val)s and ( - (from_time between %(from_time)s and %(to_time)s) or - (to_time between %(from_time)s and %(to_time)s) or - (%(from_time)s between from_time and to_time)) + (from_time > %(from_time)s and from_time < %(to_time)s) or + (to_time > %(from_time)s and to_time < %(to_time)s) or + (%(from_time)s > from_time and %(from_time)s < to_time)) and name!=%(name)s and ifnull(task, "")=%(task)s and docstatus < 2""".format(fieldname),