test: updated test for generated schedule dates
diff --git a/erpnext/maintenance/doctype/maintenance_schedule/test_maintenance_schedule.py b/erpnext/maintenance/doctype/maintenance_schedule/test_maintenance_schedule.py
index 834c054..58ee964 100644
--- a/erpnext/maintenance/doctype/maintenance_schedule/test_maintenance_schedule.py
+++ b/erpnext/maintenance/doctype/maintenance_schedule/test_maintenance_schedule.py
@@ -2,7 +2,7 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals
-from frappe.utils.data import add_days, today
+from frappe.utils.data import add_days, today, formatdate
from erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule import make_maintenance_visit
import frappe
@@ -27,6 +27,7 @@
ms = make_maintenance_schedule()
ms.save()
i = ms.items[0]
+ expected_dates = []
expected_end_date = add_days(i.start_date, i.no_of_visits * 7)
self.assertEqual(i.end_date, expected_end_date)
@@ -39,36 +40,39 @@
items = items.split('\n')
items.pop(0)
expected_items = ['_Test Item']
- self.assertTrue(items,expected_items)
+ self.assertTrue(items, expected_items)
- dates = ms.get_pending_data(data_type = "date",item_name = i.item_name)
+ # "dates" contains all generated schedule dates
+ dates = ms.get_pending_data(data_type = "date", item_name = i.item_name)
dates = dates.split('\n')
dates.pop(0)
- expected_dates = ['07-05-2021','14-05-2021']
- self.assertEqual(dates,expected_dates)
+ expected_dates.append(formatdate(add_days(i.start_date, 7), "dd-MM-yyyy"))
+ expected_dates.append(formatdate(add_days(i.start_date, 14), "dd-MM-yyyy"))
-
+ # test for generated schedule dates
+ self.assertEqual(dates, expected_dates)
+
ms.submit()
- s_id = ms.get_pending_data(data_type = "id",item_name = i.item_name, s_date = "14-05-2021")
+ s_id = ms.get_pending_data(data_type = "id", item_name = i.item_name, s_date = expected_dates[1])
test = make_maintenance_visit(source_name = ms.name, item_name = "_Test Item", s_id = s_id)
visit = frappe.new_doc('Maintenance Visit')
visit = test
visit.completion_status = "Partially Completed"
- visit.set('purposes',[{
- 'item_code':i.item_code,
- 'description':"test",
- 'work_done':"test",
- 'prevdoc_docname':ms.name,
- 'prevdoc_doctype':ms.doctype,
- 'prevdoc_detail_docname':s_id
+ visit.set('purposes', [{
+ 'item_code': i.item_code,
+ 'description': "test",
+ 'work_done': "test",
+ 'prevdoc_docname' :ms.name,
+ 'prevdoc_doctype': ms.doctype,
+ 'prevdoc_detail_docname': s_id
}])
visit.submit()
- ms = frappe.get_doc('Maintenance Schedule',ms.name)
- self.assertTrue(ms.schedules[1].completion_status,"Partially Completed")
+ ms = frappe.get_doc('Maintenance Schedule', ms.name)
+
+ #checks if visit status is back updated in schedule
+ self.assertTrue(ms.schedules[1].completion_status, "Partially Completed")
-
-
def get_events(ms):
return frappe.get_all("Event Participants", filters={
"reference_doctype": ms.doctype,
@@ -76,7 +80,6 @@
"parenttype": "Event"
})
-
def make_maintenance_schedule():
ms = frappe.new_doc("Maintenance Schedule")
ms.company = "_Test Company"