Restore staff and manager filter with performing partner support

This commit is contained in:
A R R R Associates
2026-08-05 11:58:28 +05:30
parent 5a135a65a8
commit dd2a69dbaa
+15 -2
View File
@@ -260,10 +260,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]]: def _staff_rows(db: Session, tenant_id: int | None, branch_id: int | None, tasks: list[ClientServiceTaskInstance]) -> list[dict[str, Any]]:
if not tenant_id: if not tenant_id:
return [] 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: if branch_id is not None:
stmt = stmt.where(User.branch_id == branch_id) 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]] = {} by_user: dict[int, dict[str, int]] = {}
for task in tasks: for task in tasks:
uid = getattr(task, "assigned_to_user_id", None) uid = getattr(task, "assigned_to_user_id", None)