Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(migration): resolve breaking issue in migrate_shift_assignment_schedule_to_shift_schedule.py #2566

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
import frappe

from hrms.hr.doctype.shift_schedule.shift_schedule import get_or_insert_shift_schedule


def execute():
fields = ["name", "shift_type", "frequency", "employee", "shift_status", "enabled", "create_shifts_after"]
for doc in frappe.get_all("Shift Assignment Schedule", fields=fields):
repeat_on_days = frappe.get_all(
"Assignment Rule Day", {"parent": doc.name}, pluck="day", distinct=True
)
shift_schedule_name = get_or_insert_shift_schedule(doc.shift_type, doc.frequency, repeat_on_days)
fields = ["name", "shift_type", "frequency", "employee", "shift_status", "enabled", "create_shifts_after"]

try:
shift_assignment_schedules = frappe.get_all("Shift Assignment Schedule", fields=fields)
except frappe.DoesNotExistError:
frappe.log_error("Shift Assignment Schedule DocType does not exist. Migration skipped for this DocType.", "Migration Warning")
return

for doc in shift_assignment_schedules:
try:
repeat_on_days = frappe.get_all(
"Assignment Rule Day", {"parent": doc.name}, pluck="day", distinct=True
)
shift_schedule_name = get_or_insert_shift_schedule(doc.shift_type, doc.frequency, repeat_on_days)

schedule_assignment = frappe.get_doc(
{
"doctype": "Shift Schedule Assignment",
"shift_schedule": shift_schedule_name,
"employee": doc.employee,
"shift_status": doc.shift_status,
"enabled": doc.enabled,
"create_shifts_after": doc.create_shifts_after,
}
).insert()

schedule_assignment = frappe.get_doc(
{
"doctype": "Shift Schedule Assignment",
"shift_schedule": shift_schedule_name,
"employee": doc.employee,
"shift_status": doc.shift_status,
"enabled": doc.enabled,
"create_shifts_after": doc.create_shifts_after,
}
).insert()
for d in frappe.get_all("Shift Assignment", filters={"schedule": doc.name}, pluck="name"):
frappe.db.set_value("Shift Assignment", d, "shift_schedule_assignment", schedule_assignment.name)

for d in frappe.get_all("Shift Assignment", filters={"schedule": doc.name}, pluck="name"):
frappe.db.set_value("Shift Assignment", d, "shift_schedule_assignment", schedule_assignment.name)
except Exception as e:
frappe.log_error(f"Error processing Shift Assignment Schedule {doc.name}: {str(e)}", "Migration Error")
Loading