[Tests] Shift Planning (#14570)
* Cancel shift assignment on cancellation of shift request * [minor] Fix shift type test * Modify test for shift request * Add test case for shift assignment * Fix syntax * Fix codacy
This commit is contained in:
parent
b0fafa9774
commit
cbff30f718
@ -12,7 +12,7 @@ class OverlapError(frappe.ValidationError): pass
|
|||||||
|
|
||||||
class ShiftAssignment(Document):
|
class ShiftAssignment(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_overlapping_dates();
|
self.validate_overlapping_dates()
|
||||||
|
|
||||||
def validate_overlapping_dates(self):
|
def validate_overlapping_dates(self):
|
||||||
if not self.name:
|
if not self.name:
|
||||||
|
|||||||
@ -5,6 +5,23 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
import unittest
|
import unittest
|
||||||
|
from frappe.utils import nowdate
|
||||||
|
|
||||||
|
test_dependencies = ["Shift Type"]
|
||||||
|
|
||||||
class TestShiftAssignment(unittest.TestCase):
|
class TestShiftAssignment(unittest.TestCase):
|
||||||
pass
|
|
||||||
|
def setUp(self):
|
||||||
|
frappe.db.sql("delete from `tabShift Assignment`")
|
||||||
|
|
||||||
|
def test_make_shift_assignment(self):
|
||||||
|
shift_assignment = frappe.get_doc({
|
||||||
|
"doctype": "Shift Assignment",
|
||||||
|
"shift_type": "Day Shift",
|
||||||
|
"company": "_Test Company",
|
||||||
|
"employee": "_T-Employee-00001",
|
||||||
|
"date": nowdate()
|
||||||
|
}).insert()
|
||||||
|
shift_assignment.submit()
|
||||||
|
|
||||||
|
self.assertEqual(shift_assignment.docstatus, 1)
|
||||||
|
|||||||
@ -12,8 +12,8 @@ class OverlapError(frappe.ValidationError): pass
|
|||||||
|
|
||||||
class ShiftRequest(Document):
|
class ShiftRequest(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_dates();
|
self.validate_dates()
|
||||||
self.validate_shift_request_overlap_dates();
|
self.validate_shift_request_overlap_dates()
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
date_list = self.get_working_days(self.from_date, self.to_date)
|
date_list = self.get_working_days(self.from_date, self.to_date)
|
||||||
@ -27,6 +27,14 @@ class ShiftRequest(Document):
|
|||||||
assignment_doc.insert()
|
assignment_doc.insert()
|
||||||
assignment_doc.submit()
|
assignment_doc.submit()
|
||||||
|
|
||||||
|
def on_cancel(self):
|
||||||
|
shift_assignment_list = frappe.get_list("Shift Assignment", {'employee': self.employee, 'shift_request': self.name})
|
||||||
|
if shift_assignment_list:
|
||||||
|
for shift in shift_assignment_list:
|
||||||
|
shift_assignment_doc = frappe.get_doc("Shift Assignment", shift['name'])
|
||||||
|
shift_assignment_doc.cancel()
|
||||||
|
|
||||||
|
|
||||||
def validate_dates(self):
|
def validate_dates(self):
|
||||||
if self.from_date and self.to_date and (getdate(self.to_date) < getdate(self.from_date)):
|
if self.from_date and self.to_date and (getdate(self.to_date) < getdate(self.from_date)):
|
||||||
frappe.throw(_("To date cannot be before from date"))
|
frappe.throw(_("To date cannot be before from date"))
|
||||||
|
|||||||
@ -8,6 +8,10 @@ import unittest
|
|||||||
from frappe.utils import nowdate
|
from frappe.utils import nowdate
|
||||||
|
|
||||||
class TestShiftRequest(unittest.TestCase):
|
class TestShiftRequest(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
for doctype in ["Shift Request", "Shift Assignment"]:
|
||||||
|
frappe.db.sql("delete from `tab{doctype}`".format(doctype=doctype))
|
||||||
|
|
||||||
def test_make_shift_request(self):
|
def test_make_shift_request(self):
|
||||||
shift_request = frappe.get_doc({
|
shift_request = frappe.get_doc({
|
||||||
"doctype": "Shift Request",
|
"doctype": "Shift Request",
|
||||||
@ -20,9 +24,14 @@ class TestShiftRequest(unittest.TestCase):
|
|||||||
})
|
})
|
||||||
shift_request.insert()
|
shift_request.insert()
|
||||||
shift_request.submit()
|
shift_request.submit()
|
||||||
shift_assignment = frappe.db.sql("""select employee
|
shift_assignments = frappe.db.sql('''
|
||||||
from `tabShift Assignment`
|
SELECT shift_request, employee
|
||||||
where shift_request = %s""", shift_request.name)
|
FROM `tabShift Assignment`
|
||||||
if shift_assignment:
|
WHERE shift_request = '{0}'
|
||||||
employee = shift_assignment[0][0]
|
'''.format(shift_request.name), as_dict=1)
|
||||||
self.assertEqual(shift_request.employee, employee)
|
for d in shift_assignments:
|
||||||
|
employee = d.get('employee')
|
||||||
|
self.assertEqual(shift_request.employee, employee)
|
||||||
|
shift_request.cancel()
|
||||||
|
shift_assignment_doc = frappe.get_doc("Shift Assignment", {"shift_request": d.get('shift_request')})
|
||||||
|
self.assertEqual(shift_assignment_doc.docstatus, 2)
|
||||||
@ -8,6 +8,8 @@ import unittest
|
|||||||
|
|
||||||
class TestShiftType(unittest.TestCase):
|
class TestShiftType(unittest.TestCase):
|
||||||
def test_make_shift_type(self):
|
def test_make_shift_type(self):
|
||||||
|
if frappe.db.exists("Shift Type", "Day Shift"):
|
||||||
|
return
|
||||||
shift_type = frappe.get_doc({
|
shift_type = frappe.get_doc({
|
||||||
"doctype": "Shift Type",
|
"doctype": "Shift Type",
|
||||||
"name": "Day Shift",
|
"name": "Day Shift",
|
||||||
@ -15,3 +17,4 @@ class TestShiftType(unittest.TestCase):
|
|||||||
"end_time": "18:00:00"
|
"end_time": "18:00:00"
|
||||||
})
|
})
|
||||||
shift_type.insert()
|
shift_type.insert()
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user