Skip to content

Commit

Permalink
Merge pull request #3936 from ONE-F-M/188754874
Browse files Browse the repository at this point in the history
Chore : Update operation roles of shift employee
  • Loading branch information
Talleyrand333 authored Jan 16, 2025
2 parents 4ebda06 + c522447 commit d4acae4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions one_fm/patches/v15_0/update_employees_operation_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ def execute():

# Prepare bulk update data
updates = []
employee_names = []
for schedule in results:
if schedule["schedule_shift"] and schedule["current_shift"] == schedule["schedule_shift"]:
updates.append((schedule["operations_role"], schedule["employee"]))
employee_names.append(schedule["employee"])

# Execute bulk update if there are matching records
if updates:
Expand All @@ -36,16 +38,18 @@ def execute():
update_cases.append("WHEN %s THEN %s")
employee_ids.append(employee_name) # Add employee name
employee_ids.append(operations_role) # Add corresponding operation role


# Add the WHERE clause parameters
employee_ids.extend(employee_names)

# Bulk update query
update_query = f"""
UPDATE `tabEmployee`
SET custom_operations_role_allocation = CASE name
{' '.join(update_cases)}
END
WHERE name IN ({', '.join(['%s'] * len(updates))})
WHERE name IN ({', '.join(['%s'] * len(employee_names))})
"""

# Execute the query
frappe.db.sql(update_query, tuple(employee_ids + [emp[0] for emp in updates]))
frappe.db.sql(update_query, tuple(employee_ids))
frappe.db.commit()

0 comments on commit d4acae4

Please sign in to comment.