diff --git a/helpdesk/patches/update_hd_team_users.py b/helpdesk/patches/update_hd_team_users.py index 5d34a1fe9..42ed91b06 100644 --- a/helpdesk/patches/update_hd_team_users.py +++ b/helpdesk/patches/update_hd_team_users.py @@ -6,16 +6,21 @@ def execute(): for team in teams: existing_agents = frappe.get_all( "HD Team Item", filters={"team": team}, pluck="parent" - ) + ) # agents in HD Agent doctype team_users = frappe.get_all( "HD Team Member", filters={"parent": team}, pluck="user" - ) + ) # agents in HD Team doctype 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") + is_agent_active = frappe.get_value("HD Agent", agent, "is_active") + if not is_agent_active: + continue + + if is_agent_active: + if agent not in team_users: + team_doc = ( + frappe.get_doc("HD Team", team) + .append("users", {"user": agent}) + .save() + ) + print("Agent Added")