def build_client_association(current_user, role_name, selected_partner_id=None): role = (role_name or '').lower() if role in ('system admin', 'firm admin'): return { 'association_type': 'firm', 'firm_tenant_id': getattr(current_user, 'tenant_id', None), 'partner_user_id': selected_partner_id, 'created_source': 'firm_admin', } if role == 'partner': return { 'association_type': 'firm', 'firm_tenant_id': getattr(current_user, 'tenant_id', None), 'partner_user_id': current_user.id, 'created_source': 'partner', } if role == 'consultant': return { 'association_type': 'consultant', 'consultant_id': current_user.id, 'created_source': 'consultant', } return { 'association_type': 'self_service_unassigned', 'created_source': 'self_service', }