"From time" cannot be later than "To time" and hours cannot be negative
This commit is contained in:
parent
3d65d9602e
commit
83db3e3ddb
@ -17,5 +17,14 @@ class TestTimeLog(unittest.TestCase):
|
|||||||
|
|
||||||
frappe.db.sql("delete from `tabTime Log`")
|
frappe.db.sql("delete from `tabTime Log`")
|
||||||
|
|
||||||
|
def test_negative_hours(self):
|
||||||
|
frappe.db.sql("delete from `tabTime Log`")
|
||||||
|
test_time_log = frappe.new_doc("Time Log")
|
||||||
|
test_time_log.activity_type = "Communication"
|
||||||
|
test_time_log.from_time = "2013-01-01 11:00:00.000000"
|
||||||
|
test_time_log.to_time = "2013-01-01 10:00:00.000000"
|
||||||
|
self.assertRaises(frappe.ValidationError, test_time_log.save)
|
||||||
|
frappe.db.sql("delete from `tabTime Log`")
|
||||||
|
|
||||||
test_records = frappe.get_test_records('Time Log')
|
test_records = frappe.get_test_records('Time Log')
|
||||||
test_ignore = ["Time Log Batch", "Sales Invoice"]
|
test_ignore = ["Time Log Batch", "Sales Invoice"]
|
||||||
|
|||||||
@ -23,6 +23,8 @@ class TimeLog(Document):
|
|||||||
def calculate_total_hours(self):
|
def calculate_total_hours(self):
|
||||||
from frappe.utils import time_diff_in_hours
|
from frappe.utils import time_diff_in_hours
|
||||||
self.hours = time_diff_in_hours(self.to_time, self.from_time)
|
self.hours = time_diff_in_hours(self.to_time, self.from_time)
|
||||||
|
if self.hours < 0:
|
||||||
|
frappe.throw(_("\'From Time\' cannot be later than \'To Time\'"))
|
||||||
|
|
||||||
def set_status(self):
|
def set_status(self):
|
||||||
self.status = {
|
self.status = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user