From ef3d3e87b61c4820fc97997907ce9018bd764991 Mon Sep 17 00:00:00 2001 From: RitvikSardana Date: Mon, 11 Nov 2024 16:48:14 +0530 Subject: [PATCH] fix(patch): add patch for updating HD Team --- helpdesk/helpdesk/doctype/hd_team/hd_team.py | 6 ++---- helpdesk/patches/update_hd_team_users.py | 21 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 helpdesk/patches/update_hd_team_users.py diff --git a/helpdesk/helpdesk/doctype/hd_team/hd_team.py b/helpdesk/helpdesk/doctype/hd_team/hd_team.py index a40805d70..86bcdbd68 100644 --- a/helpdesk/helpdesk/doctype/hd_team/hd_team.py +++ b/helpdesk/helpdesk/doctype/hd_team/hd_team.py @@ -28,7 +28,6 @@ def on_update(self): self.update_support_rotations() def on_trash(self): - # Deletes the assignment rule for this group try: frappe.delete_doc("Assignment Rule", self.assignment_rule) @@ -78,9 +77,8 @@ def get_assignment_rule(self): def update_support_rotations(self): """ Update the support rotations for the hd_agent - # If agent removed remove from the support rule of the team - # If agent added add to the support rule of the team - # while adding remove from base Support Rotation + # If agent removed, remove from the support rule of the team + # If agent added add to the support rule of the team and also, while adding remove from base Support Rotation """ assg_rule_doc = frappe.get_doc("Assignment Rule", self.assignment_rule) if not assg_rule_doc: diff --git a/helpdesk/patches/update_hd_team_users.py b/helpdesk/patches/update_hd_team_users.py new file mode 100644 index 000000000..5d34a1fe9 --- /dev/null +++ b/helpdesk/patches/update_hd_team_users.py @@ -0,0 +1,21 @@ +import frappe + + +def execute(): + teams = frappe.get_all("HD Team", pluck="name") + for team in teams: + existing_agents = frappe.get_all( + "HD Team Item", filters={"team": team}, pluck="parent" + ) + team_users = frappe.get_all( + "HD Team Member", filters={"parent": team}, pluck="user" + ) + + for agent in existing_agents: + if agent not in team_users: + team_doc = ( + frappe.get_doc("HD Team", team) + .append("users", {"user": agent}) + .save() + ) + print("Agent Added")