315 lines
10 KiB
Python
315 lines
10 KiB
Python
import arrow
|
|
|
|
from Modules.Token.password_module import PasswordModule
|
|
from Controllers.Mongo.database import mongo_handler
|
|
|
|
|
|
def create_occupant_defaults(db_session):
|
|
from Schemas import (
|
|
Addresses,
|
|
BuildLivingSpace,
|
|
Users,
|
|
People,
|
|
Build,
|
|
BuildParts,
|
|
BuildTypes,
|
|
ApiEnumDropdown,
|
|
Companies,
|
|
OccupantTypes,
|
|
)
|
|
|
|
created_list = []
|
|
|
|
company_management = Companies.filter_one(
|
|
Companies.formal_name == "Evyos LTD",
|
|
db=db_session,
|
|
).data
|
|
|
|
if not company_management:
|
|
raise Exception("Company not found")
|
|
|
|
company_id, company_uu_id = company_management.id, str(company_management.uu_id)
|
|
active_row = dict(
|
|
is_confirmed=True,
|
|
active=True,
|
|
deleted=False,
|
|
is_notification_send=True,
|
|
)
|
|
build_type = BuildTypes.filter_one(
|
|
BuildTypes.type_code == "APT",
|
|
db=db_session,
|
|
).data
|
|
address = Addresses.filter_one(
|
|
Addresses.letter_address == "Example Address",
|
|
db=db_session,
|
|
).data
|
|
|
|
created_build = Build.find_or_create(
|
|
build_name="Build Example",
|
|
build_code="B001",
|
|
build_no="B001",
|
|
build_date="01.07.1980",
|
|
address_id=address.id,
|
|
address_uu_id=str(address.uu_id),
|
|
company_id=company_id,
|
|
build_types_id=build_type.id,
|
|
build_types_uu_id=str(build_type.uu_id),
|
|
company_uu_id=str(company_uu_id),
|
|
**active_row,
|
|
db=db_session,
|
|
)
|
|
created_list.append(created_build)
|
|
|
|
build_type_created = BuildTypes.filter_one(
|
|
BuildTypes.type_code == "APT",
|
|
db=db_session,
|
|
).data
|
|
build_type_flat = BuildTypes.filter_one(
|
|
BuildTypes.type_code == "DAIRE",
|
|
db=db_session,
|
|
).data
|
|
|
|
enum_dropdown = ApiEnumDropdown.filter_one(
|
|
ApiEnumDropdown.key == "NE",
|
|
ApiEnumDropdown.enum_class == "Directions",
|
|
db=db_session,
|
|
).data
|
|
|
|
occupant_type_prs = OccupantTypes.filter_one(
|
|
OccupantTypes.occupant_code == "MT-PRS",
|
|
db=db_session,
|
|
).data
|
|
occupant_type_owner = OccupantTypes.filter_one(
|
|
OccupantTypes.occupant_code == "FL-OWN",
|
|
db=db_session,
|
|
).data
|
|
occupant_type_tenant = OccupantTypes.filter_one(
|
|
OccupantTypes.occupant_code == "FL-TEN",
|
|
db=db_session,
|
|
).data
|
|
|
|
created_managment_room = BuildParts.find_or_create(
|
|
address_gov_code="123123123123",
|
|
build_id=created_build.id,
|
|
build_uu_id=str(created_build.uu_id),
|
|
part_code="MR001",
|
|
part_net_size=100,
|
|
part_no=0,
|
|
part_level=0,
|
|
part_type_id=build_type_created.id,
|
|
part_type_uu_id=str(build_type_created.uu_id),
|
|
part_direction_id=enum_dropdown.id,
|
|
part_direction_uu_id=str(enum_dropdown.uu_id),
|
|
human_livable=True,
|
|
due_part_key="Example",
|
|
**active_row,
|
|
db=db_session,
|
|
)
|
|
created_list.append(created_managment_room)
|
|
created_flat = BuildParts.find_or_create(
|
|
address_gov_code="123123123124",
|
|
build_id=created_build.id,
|
|
build_uu_id=str(created_build.uu_id),
|
|
part_code="MF001",
|
|
part_net_size=100,
|
|
part_no=1,
|
|
part_level=1,
|
|
part_type_id=build_type_flat.id,
|
|
part_type_uu_id=str(build_type_flat.uu_id),
|
|
part_direction_id=enum_dropdown.id,
|
|
part_direction_uu_id=str(enum_dropdown.uu_id),
|
|
human_livable=True,
|
|
due_part_key="Example",
|
|
**active_row,
|
|
db=db_session,
|
|
)
|
|
created_list.append(created_flat)
|
|
|
|
build_manager_people = People.find_or_create(
|
|
**{
|
|
"person_tag": "Build Manager Example",
|
|
"firstname": "Example Build Manager",
|
|
"surname": "Example",
|
|
"sex_code": "M",
|
|
"middle_name": "",
|
|
"father_name": "Father",
|
|
"mother_name": "Mother",
|
|
"country_code": "TR",
|
|
"national_identity_id": "12312312315",
|
|
"birth_place": "Ankara",
|
|
"birth_date": "01.07.1990",
|
|
"tax_no": "1231231234",
|
|
},
|
|
db=db_session,
|
|
)
|
|
created_list.append(build_manager_people)
|
|
owner_people = People.find_or_create(
|
|
**{
|
|
"person_tag": "Owner Example",
|
|
"firstname": "Example Owner",
|
|
"surname": "Example",
|
|
"sex_code": "M",
|
|
"middle_name": "",
|
|
"father_name": "Father",
|
|
"mother_name": "Mother",
|
|
"country_code": "TR",
|
|
"national_identity_id": "12312312316",
|
|
"birth_place": "Ankara",
|
|
"birth_date": "01.07.1990",
|
|
"tax_no": "1231231234",
|
|
},
|
|
db=db_session,
|
|
)
|
|
created_list.append(owner_people)
|
|
tenant_people = People.find_or_create(
|
|
**{
|
|
"person_tag": "Tenant Example",
|
|
"firstname": "Example Tenant",
|
|
"surname": "Example",
|
|
"sex_code": "M",
|
|
"middle_name": "",
|
|
"father_name": "Father",
|
|
"mother_name": "Mother",
|
|
"country_code": "TR",
|
|
"national_identity_id": "12312312317",
|
|
"birth_place": "Ankara",
|
|
"birth_date": "01.07.1990",
|
|
"tax_no": "1231231234",
|
|
},
|
|
db=db_session,
|
|
)
|
|
created_list.append(tenant_people)
|
|
main_domain, collection_name = (
|
|
"evyos.com.tr",
|
|
f"{str(company_management.uu_id)}*Domain",
|
|
)
|
|
|
|
user_build_manager = Users.find_or_create(
|
|
person_id=build_manager_people.id,
|
|
person_uu_id=str(build_manager_people.uu_id),
|
|
user_tag=build_manager_people.person_tag,
|
|
email="example.build.manager@gmail.com",
|
|
phone_number="+901111111111",
|
|
avatar="https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg",
|
|
related_company=str(company_management.uu_id),
|
|
is_confirmed=True,
|
|
active=True,
|
|
deleted=False,
|
|
is_notification_send=True,
|
|
db=db_session,
|
|
)
|
|
created_list.append(user_build_manager)
|
|
user_build_manager.password_expiry_begins = str(arrow.now())
|
|
user_build_manager.password_token = PasswordModule.generate_refresher_token()
|
|
|
|
user_owner = Users.find_or_create(
|
|
person_id=owner_people.id,
|
|
person_uu_id=str(owner_people.uu_id),
|
|
user_tag=owner_people.person_tag,
|
|
email="example.owner@gmail.com",
|
|
phone_number="+901111111111",
|
|
avatar="https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg",
|
|
related_company=str(company_management.uu_id),
|
|
is_confirmed=True,
|
|
active=True,
|
|
deleted=False,
|
|
is_notification_send=True,
|
|
db=db_session,
|
|
)
|
|
created_list.append(user_owner)
|
|
user_owner.password_expiry_begins = str(arrow.now())
|
|
user_owner.password_token = PasswordModule.generate_refresher_token()
|
|
|
|
user_tenant = Users.find_or_create(
|
|
person_id=tenant_people.id,
|
|
person_uu_id=str(tenant_people.uu_id),
|
|
user_tag=tenant_people.person_tag,
|
|
email="example.tenant@gmail.com",
|
|
phone_number="+901111111111",
|
|
avatar="https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg",
|
|
related_company=str(company_management.uu_id),
|
|
is_confirmed=True,
|
|
active=True,
|
|
deleted=False,
|
|
is_notification_send=True,
|
|
db=db_session,
|
|
)
|
|
created_list.append(user_tenant)
|
|
user_tenant.password_expiry_begins = str(arrow.now())
|
|
user_tenant.password_token = PasswordModule.generate_refresher_token()
|
|
|
|
with mongo_handler.collection(collection_name) as mongo_engine:
|
|
mongo_engine.insert_one(
|
|
document={
|
|
"user_uu_id": str(user_build_manager.uu_id),
|
|
"other_domains_list": [main_domain],
|
|
"main_domain": main_domain,
|
|
"modified_at": arrow.now().timestamp(),
|
|
}
|
|
)
|
|
|
|
with mongo_handler.collection(collection_name) as mongo_engine:
|
|
mongo_engine.insert_one(
|
|
document={
|
|
"user_uu_id": str(user_owner.uu_id),
|
|
"other_domains_list": [main_domain],
|
|
"main_domain": main_domain,
|
|
"modified_at": arrow.now().timestamp(),
|
|
}
|
|
)
|
|
|
|
with mongo_handler.collection(collection_name) as mongo_engine:
|
|
mongo_engine.insert_one(
|
|
document={
|
|
"user_uu_id": str(user_tenant.uu_id),
|
|
"other_domains_list": [main_domain],
|
|
"main_domain": main_domain,
|
|
"modified_at": arrow.now().timestamp(),
|
|
}
|
|
)
|
|
|
|
created_build_living_space_prs = BuildLivingSpace.find_or_create(
|
|
build_id=created_build.id,
|
|
build_uu_id=str(created_build.uu_id),
|
|
build_parts_id=created_managment_room.id,
|
|
build_parts_uu_id=str(created_managment_room.uu_id),
|
|
person_id=build_manager_people.id,
|
|
person_uu_id=str(build_manager_people.uu_id),
|
|
occupant_type_id=occupant_type_prs.id,
|
|
occupant_type_uu_id=str(occupant_type_prs.uu_id),
|
|
**active_row,
|
|
db=db_session,
|
|
)
|
|
created_list.append(created_build_living_space_prs)
|
|
|
|
created_build_living_space_owner = BuildLivingSpace.find_or_create(
|
|
build_id=created_build.id,
|
|
build_uu_id=str(created_build.uu_id),
|
|
build_parts_id=created_flat.id,
|
|
build_parts_uu_id=str(created_flat.uu_id),
|
|
person_id=owner_people.id,
|
|
person_uu_id=str(owner_people.uu_id),
|
|
occupant_type_id=occupant_type_owner.id,
|
|
occupant_type_uu_id=str(occupant_type_owner.uu_id),
|
|
**active_row,
|
|
db=db_session,
|
|
)
|
|
created_list.append(created_build_living_space_owner)
|
|
|
|
created_build_living_space_tenant = BuildLivingSpace.find_or_create(
|
|
build_id=created_build.id,
|
|
build_uu_id=str(created_build.uu_id),
|
|
build_parts_id=created_flat.id,
|
|
build_parts_uu_id=str(created_flat.uu_id),
|
|
person_id=tenant_people.id,
|
|
person_uu_id=str(tenant_people.uu_id),
|
|
occupant_type_id=occupant_type_tenant.id,
|
|
occupant_type_uu_id=str(occupant_type_tenant.uu_id),
|
|
**active_row,
|
|
db=db_session,
|
|
)
|
|
created_list.append(created_build_living_space_tenant)
|
|
|
|
db_session.commit()
|
|
print("Occupant Defaults Create is now completed")
|