fix(Timesheets): calculate to time (#28589)
Co-authored-by: Ankush Menat <ankushmenat@gmail.com> Co-authored-by: barredterra <14891507+barredterra@users.noreply.github.com>
This commit is contained in:
parent
0666996e4e
commit
f5ed0c83b7
@ -5,7 +5,7 @@ import datetime
|
||||
import unittest
|
||||
|
||||
import frappe
|
||||
from frappe.utils import add_months, now_datetime, nowdate
|
||||
from frappe.utils import add_months, add_to_date, now_datetime, nowdate
|
||||
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||
from erpnext.hr.doctype.employee.test_employee import make_employee
|
||||
@ -151,6 +151,27 @@ class TestTimesheet(unittest.TestCase):
|
||||
settings.ignore_employee_time_overlap = initial_setting
|
||||
settings.save()
|
||||
|
||||
def test_to_time(self):
|
||||
emp = make_employee("test_employee_6@salary.com")
|
||||
from_time = now_datetime()
|
||||
|
||||
timesheet = frappe.new_doc("Timesheet")
|
||||
timesheet.employee = emp
|
||||
timesheet.append(
|
||||
'time_logs',
|
||||
{
|
||||
"billable": 1,
|
||||
"activity_type": "_Test Activity Type",
|
||||
"from_time": from_time,
|
||||
"hours": 2,
|
||||
"company": "_Test Company"
|
||||
}
|
||||
)
|
||||
timesheet.save()
|
||||
|
||||
to_time = timesheet.time_logs[0].to_time
|
||||
self.assertEqual(to_time, add_to_date(from_time, hours=2, as_datetime=True))
|
||||
|
||||
|
||||
def make_salary_structure_for_timesheet(employee, company=None):
|
||||
salary_structure_name = "Timesheet Salary Structure Test"
|
||||
|
@ -7,7 +7,7 @@ import json
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import flt, getdate, time_diff_in_hours
|
||||
from frappe.utils import add_to_date, flt, getdate, time_diff_in_hours
|
||||
|
||||
from erpnext.controllers.queries import get_match_cond
|
||||
from erpnext.hr.utils import validate_active_employee
|
||||
@ -136,10 +136,19 @@ class Timesheet(Document):
|
||||
|
||||
def validate_time_logs(self):
|
||||
for data in self.get('time_logs'):
|
||||
self.set_to_time(data)
|
||||
self.validate_overlap(data)
|
||||
self.set_project(data)
|
||||
self.validate_project(data)
|
||||
|
||||
def set_to_time(self, data):
|
||||
if not (data.from_time and data.hours):
|
||||
return
|
||||
|
||||
_to_time = add_to_date(data.from_time, hours=data.hours, as_datetime=True)
|
||||
if data.to_time != _to_time:
|
||||
data.to_time = _to_time
|
||||
|
||||
def validate_overlap(self, data):
|
||||
settings = frappe.get_single('Projects Settings')
|
||||
self.validate_overlap_for("user", data, self.user, settings.ignore_user_time_overlap)
|
||||
|
Loading…
x
Reference in New Issue
Block a user