Filter partner workload to staff and managers

This commit is contained in:
A R R R Associates
2026-08-05 06:23:34 +05:30
parent 9abe68d695
commit 5107b1b139
2 changed files with 17 additions and 4 deletions
+15 -2
View File
@@ -258,10 +258,23 @@ def _load_clients(db: Session, tenant_id: int | None, branch_id: int | None, cur
def _staff_rows(db: Session, tenant_id: int | None, branch_id: int | None, tasks: list[ClientServiceTaskInstance]) -> list[dict[str, Any]]:
if not tenant_id:
return []
stmt = select(User).where(User.tenant_id == tenant_id, User.is_active.is_(True))
stmt = (
select(User)
.join(UserRole, UserRole.user_id == User.id)
.join(Role, Role.id == UserRole.role_id)
.where(
User.tenant_id == tenant_id,
User.is_active.is_(True),
Role.is_active.is_(True),
Role.name.in_(("Staff", "Branch Manager")),
)
.distinct()
)
if branch_id is not None:
stmt = stmt.where(User.branch_id == branch_id)
users = db.execute(stmt.order_by(User.full_name.asc(), User.email.asc()).limit(100)).scalars().all()
users = db.execute(
stmt.order_by(User.full_name.asc(), User.email.asc()).limit(100)
).scalars().all()
by_user: dict[int, dict[str, int]] = {}
for task in tasks:
uid = getattr(task, "assigned_to_user_id", None)