Merge pull request #3650 from rmehta/time-log-fix-2

[fix] overlap fix in time log #3647
This commit is contained in:
Anand Doshi 2015-07-14 11:45:49 +05:30
commit 41d3e57702

View File

@ -73,18 +73,20 @@ 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) or
(%(from_time)s = from_time and %(to_time)s = to_time))
and name!=%(name)s
and ifnull(task, "")=%(task)s
and docstatus < 2""".format(fieldname),