Fix Client Groups circular imports and module dependencies
This commit is contained in:
@@ -30,11 +30,16 @@ from app.modules.core.iam.models import User
|
||||
from app.modules.core.rbac.models import Role, UserRole
|
||||
from app.modules.documents.models import PermanentClientDocument
|
||||
from app.modules.consultants.service import sync_primary_client_consultant_link
|
||||
from app.modules.client_groups.service import get_group
|
||||
|
||||
from app.modules.clients.models import Client
|
||||
|
||||
|
||||
|
||||
|
||||
def _get_client_group(*args, **kwargs):
|
||||
# Imported lazily to prevent clients ↔ client_groups circular imports.
|
||||
from app.modules.client_groups.service import get_group
|
||||
return get_group(*args, **kwargs)
|
||||
def _payload_from_schema(data):
|
||||
payload = data.model_dump(exclude_none=True) if hasattr(data, "model_dump") else data.dict(exclude_none=True)
|
||||
# primary_consultant_id belongs to ClientConsultantLink, not the clients table.
|
||||
@@ -50,7 +55,7 @@ def _validate_client_group_assignment(db, *, payload: dict, existing_row=None):
|
||||
group_id = payload.get("client_group_id")
|
||||
tenant_id = payload.get("tenant_id") or getattr(existing_row, "tenant_id", None)
|
||||
if group_id:
|
||||
group = get_group(db, tenant_id=int(tenant_id), group_id=int(group_id))
|
||||
group = _get_client_group(db, tenant_id=int(tenant_id), group_id=int(group_id))
|
||||
if not group or not group.is_active:
|
||||
raise HTTPException(status_code=400, detail="Selected client group is invalid or inactive for this firm.")
|
||||
if payload.get("is_group_head") and group_id:
|
||||
|
||||
Reference in New Issue
Block a user