take joining date into consideration while assigning duties

This commit is contained in:
Pranav Jerry 2023-05-22 19:57:32 +05:30
parent 80959a8312
commit a25d9a04a4
Signed by: pranav
GPG Key ID: F1DCDC4FED0A0C5B
1 changed files with 14 additions and 3 deletions

View File

@ -3,6 +3,7 @@
import frappe
from frappe.model.document import Document
from operator import itemgetter
class ExamGroup(Document):
@ -132,11 +133,21 @@ class ExamGroup(Document):
print(total_invigilators_required)
for i in range(total_invigilators_required):
if not all_staff:
# (
# (count, date, staff),
# (count, date, staff),
# ...
# )
all_staff = frappe.db.get_list(
"Staff", pluck="name", order_by="duty_count asc"
"Staff", as_list=True, fields=["duty_count", "joining_date", "name"]
)
staff = all_staff.pop(0)
all_staff = list(all_staff)
# sort in ascending order of count
all_staff.sort(key=itemgetter(0))
# then by descending order of joining date
all_staff.sort(key=itemgetter(1), reverse=True)
print(all_staff)
staff = all_staff.pop(0)[2]
staff = frappe.get_doc("Staff", staff)
print(staff)
invigilator_child = frappe.new_doc("Invigilator And Duty")