Add performing partner to clients and engagements

This commit is contained in:
A R R R Associates
2026-08-05 10:52:36 +05:30
parent 9bfc666dad
commit 5a135a65a8
16 changed files with 122 additions and 21 deletions
+4 -15
View File
@@ -138,6 +138,7 @@ def _task_scope(stmt, tenant_id: int | None, branch_id: int | None, current_user
ClientServiceTaskInstance.subscription.has(
or_(
ClientServiceSubscription.assigned_partner_user_id == current_user.id,
ClientServiceSubscription.performing_partner_user_id == current_user.id,
ClientServiceSubscription.review_partner_user_id == current_user.id,
)
)
@@ -157,6 +158,7 @@ def _subscription_scope(stmt, tenant_id: int | None, branch_id: int | None, curr
stmt = stmt.where(
or_(
ClientServiceSubscription.assigned_partner_user_id == current_user.id,
ClientServiceSubscription.performing_partner_user_id == current_user.id,
ClientServiceSubscription.review_partner_user_id == current_user.id,
)
)
@@ -258,23 +260,10 @@ 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)
.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()
)
stmt = select(User).where(User.tenant_id == tenant_id, User.is_active.is_(True))
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)