mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-13 10:11:20 +00:00
fix(Timesheet): convert time logs to datetime while checking for overlap
This commit is contained in:
@@ -7,7 +7,7 @@ import json
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import add_to_date, flt, getdate, time_diff_in_hours
|
from frappe.utils import add_to_date, flt, get_datetime, getdate, time_diff_in_hours
|
||||||
|
|
||||||
from erpnext.controllers.queries import get_match_cond
|
from erpnext.controllers.queries import get_match_cond
|
||||||
from erpnext.hr.utils import validate_active_employee
|
from erpnext.hr.utils import validate_active_employee
|
||||||
@@ -145,7 +145,7 @@ class Timesheet(Document):
|
|||||||
if not (data.from_time and data.hours):
|
if not (data.from_time and data.hours):
|
||||||
return
|
return
|
||||||
|
|
||||||
_to_time = add_to_date(data.from_time, hours=data.hours, as_datetime=True)
|
_to_time = get_datetime(add_to_date(data.from_time, hours=data.hours, as_datetime=True))
|
||||||
if data.to_time != _to_time:
|
if data.to_time != _to_time:
|
||||||
data.to_time = _to_time
|
data.to_time = _to_time
|
||||||
|
|
||||||
@@ -186,24 +186,37 @@ class Timesheet(Document):
|
|||||||
and ts.docstatus < 2""".format(cond),
|
and ts.docstatus < 2""".format(cond),
|
||||||
{
|
{
|
||||||
"val": value,
|
"val": value,
|
||||||
"from_time": args.from_time,
|
"from_time": get_datetime(args.from_time),
|
||||||
"to_time": args.to_time,
|
"to_time": get_datetime(args.to_time),
|
||||||
"name": args.name or "No Name",
|
"name": args.name or "No Name",
|
||||||
"parent": args.parent or "No Name"
|
"parent": args.parent or "No Name"
|
||||||
}, as_dict=True)
|
}, as_dict=True)
|
||||||
# check internal overlap
|
|
||||||
for time_log in self.time_logs:
|
|
||||||
if not (time_log.from_time and time_log.to_time
|
|
||||||
and args.from_time and args.to_time): continue
|
|
||||||
|
|
||||||
if (fieldname != 'workstation' or args.get(fieldname) == time_log.get(fieldname)) and \
|
if self.check_internal_overlap(fieldname, args):
|
||||||
args.idx != time_log.idx and ((args.from_time > time_log.from_time and args.from_time < time_log.to_time) or
|
return self
|
||||||
(args.to_time > time_log.from_time and args.to_time < time_log.to_time) or
|
|
||||||
(args.from_time <= time_log.from_time and args.to_time >= time_log.to_time)):
|
|
||||||
return self
|
|
||||||
|
|
||||||
return existing[0] if existing else None
|
return existing[0] if existing else None
|
||||||
|
|
||||||
|
def check_internal_overlap(self, fieldname, args):
|
||||||
|
for time_log in self.time_logs:
|
||||||
|
if not (time_log.from_time and time_log.to_time
|
||||||
|
and args.from_time and args.to_time):
|
||||||
|
continue
|
||||||
|
|
||||||
|
from_time = get_datetime(time_log.from_time)
|
||||||
|
to_time = get_datetime(time_log.to_time)
|
||||||
|
args_from_time = get_datetime(args.from_time)
|
||||||
|
args_to_time = get_datetime(args.to_time)
|
||||||
|
|
||||||
|
if (fieldname != 'workstation' or args.get(fieldname) == time_log.get(fieldname)) and \
|
||||||
|
args.idx != time_log.idx and (
|
||||||
|
(args_from_time > from_time and args_from_time < to_time)
|
||||||
|
or (args_to_time > from_time and args_to_time < to_time)
|
||||||
|
or (args_from_time <= from_time and args_to_time >= to_time)
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def update_cost(self):
|
def update_cost(self):
|
||||||
for data in self.time_logs:
|
for data in self.time_logs:
|
||||||
if data.activity_type or data.is_billable:
|
if data.activity_type or data.is_billable:
|
||||||
|
|||||||
Reference in New Issue
Block a user