54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
import typing
|
|
|
|
from apps.authentication.models import Organization, OrganizationType
|
|
|
|
|
|
def get_users_of_organization(org: Organization) -> typing.Any:
|
|
""" get users of an organizations """
|
|
user_relations = org.user_organization.all()
|
|
|
|
users_list = [{
|
|
'name': f"{rel.user.first_name} {rel.user.last_name}",
|
|
'national_code': rel.user.national_code,
|
|
'mobile': rel.user.mobile,
|
|
'phone': rel.user.phone,
|
|
'address': rel.user.address
|
|
} for rel in user_relations]
|
|
|
|
return users_list
|
|
|
|
|
|
def get_all_org_child(org: Organization = None) -> typing.Any:
|
|
"""
|
|
get all child of an organization
|
|
"""
|
|
descendants = []
|
|
children = org.parents.all()
|
|
for child in children:
|
|
descendants.append(child)
|
|
descendants.extend(get_all_org_child(child))
|
|
return descendants
|
|
|
|
|
|
def get_all_org_type_child(org_type: OrganizationType = None) -> typing.Any:
|
|
"""
|
|
get all child of an organization
|
|
"""
|
|
descendants = []
|
|
children = org_type.children.all()
|
|
for child in children:
|
|
descendants.append(child)
|
|
descendants.extend(get_all_org_type_child(child))
|
|
return descendants
|
|
|
|
|
|
def get_bank_info(org):
|
|
bank = org.bank_information.first()
|
|
if not bank:
|
|
return {}
|
|
return {
|
|
"credit_card": bank.card,
|
|
"sheba": f"IR{bank.sheba}",
|
|
"account": bank.account,
|
|
}
|