save and confirmed added
This commit is contained in:
@@ -107,11 +107,15 @@ class AccountRecordsCreateEventMethods(MethodToEvent):
|
||||
data_dict["bank_date_y"] = bank_date.year
|
||||
|
||||
if int(data.currency_value) < 0:
|
||||
debit_type = ApiEnumDropdown.filter_by_one(system=True, enum_class="DebitTypes", key="DT-D").data
|
||||
debit_type = ApiEnumDropdown.filter_by_one(
|
||||
system=True, enum_class="DebitTypes", key="DT-D"
|
||||
).data
|
||||
data_dict["receive_debit"] = debit_type.id
|
||||
data_dict["receive_debit_uu_id"] = str(debit_type.uu_id)
|
||||
else:
|
||||
debit_type = ApiEnumDropdown.filter_by_one(system=True, enum_class="DebitTypes", key="DT-R").data
|
||||
debit_type = ApiEnumDropdown.filter_by_one(
|
||||
system=True, enum_class="DebitTypes", key="DT-R"
|
||||
).data
|
||||
data_dict["receive_debit"] = debit_type.id
|
||||
data_dict["receive_debit_uu_id"] = str(debit_type.uu_id)
|
||||
|
||||
|
||||
@@ -66,8 +66,7 @@ class AddressListEventMethods(MethodToEvent):
|
||||
Addresses.street_id.in_(get_street_ids),
|
||||
).query
|
||||
Addresses.filter_attr = list_options
|
||||
records = Addresses.filter_all(
|
||||
).data
|
||||
records = Addresses.filter_all().data
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
message="List Address records",
|
||||
|
||||
@@ -202,12 +202,9 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Build Part is not found",
|
||||
)
|
||||
build = Build.filter_one(
|
||||
Build.id == build_part.build_id
|
||||
).data
|
||||
build = Build.filter_one(Build.id == build_part.build_id).data
|
||||
related_company = RelationshipEmployee2Build.filter_one(
|
||||
RelationshipEmployee2Build.member_id == build.id,
|
||||
|
||||
).data
|
||||
company_related = Companies.filter_one(
|
||||
Companies.id == related_company.company_id,
|
||||
@@ -340,9 +337,7 @@ class AuthenticationChangePasswordEventMethods(MethodToEvent):
|
||||
):
|
||||
token_user = get_object_via_access_key(request=request)
|
||||
if token_user.user_type == 1:
|
||||
if found_user := Users.filter_one(
|
||||
Users.uu_id == token_user.uu_id
|
||||
).data:
|
||||
if found_user := Users.filter_one(Users.uu_id == token_user.uu_id).data:
|
||||
if found_user.check_password(data.old_password):
|
||||
found_user.set_password(data.new_password)
|
||||
return JSONResponse(
|
||||
@@ -427,9 +422,7 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
|
||||
):
|
||||
|
||||
if token_user := get_object_via_access_key(request=request):
|
||||
found_user = Users.filter_one(
|
||||
Users.uu_id == token_user.get("uu_id")
|
||||
).data
|
||||
found_user = Users.filter_one(Users.uu_id == token_user.get("uu_id")).data
|
||||
if not found_user:
|
||||
return JSONResponse(
|
||||
content={
|
||||
|
||||
@@ -102,7 +102,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
cls,
|
||||
request: Request,
|
||||
data: Union[EmployeeSelection, OccupantSelection],
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
from api_objects import OccupantToken, CompanyToken
|
||||
|
||||
@@ -152,9 +152,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
department = Departments.filter_one(
|
||||
Departments.id == duties.department_id,
|
||||
).data
|
||||
bulk_id = Duty.filter_by_one(
|
||||
system=True, duty_code="BULK"
|
||||
).data
|
||||
bulk_id = Duty.filter_by_one(system=True, duty_code="BULK").data
|
||||
bulk_duty_id = Duties.filter_by_one(
|
||||
company_id=selected_company.id,
|
||||
duties_id=bulk_id.id,
|
||||
|
||||
@@ -214,7 +214,7 @@ class BuildPatchEventMethods(MethodToEvent):
|
||||
@classmethod
|
||||
def build_patch(cls, build_uu_id: str, data: PatchRecord, token_dict):
|
||||
find_one_build = Build.filter_one(
|
||||
Build.uu_id==build_uu_id,
|
||||
Build.uu_id == build_uu_id,
|
||||
)
|
||||
access_authorized_build = Build.select_action(
|
||||
employee_id=token_dict.selected_company.employee_id,
|
||||
|
||||
@@ -75,7 +75,9 @@ class BuildAreaCreateEventMethods(MethodToEvent):
|
||||
"build_uu_id": data.build_uu_id,
|
||||
},
|
||||
)
|
||||
selected_build = Build.filter_by_one(system=True, uu_id=data.build_uu_id).data
|
||||
selected_build = Build.filter_by_one(
|
||||
system=True, uu_id=data.build_uu_id
|
||||
).data
|
||||
elif isinstance(token_dict, EmployeeTokenObject):
|
||||
build_ids = Build.select_action(
|
||||
employee_id=token_dict.selected_company.employee_id
|
||||
@@ -89,7 +91,9 @@ class BuildAreaCreateEventMethods(MethodToEvent):
|
||||
"build_uu_id": data.build_uu_id,
|
||||
},
|
||||
)
|
||||
selected_build = Build.filter_by_one(system=True, uu_id=data.build_uu_id).data
|
||||
selected_build = Build.filter_by_one(
|
||||
system=True, uu_id=data.build_uu_id
|
||||
).data
|
||||
|
||||
data_dict["build_id"] = selected_build.id
|
||||
data_dict["build_uu_id"] = str(selected_build.uu_id)
|
||||
|
||||
@@ -18,11 +18,12 @@ class BuildTypesListEventMethods(MethodToEvent):
|
||||
|
||||
@classmethod
|
||||
def build_types_list(
|
||||
cls,
|
||||
list_options: ListOptions,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||
cls,
|
||||
list_options: ListOptions,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
from fastapi.exceptions import HTTPException
|
||||
|
||||
if isinstance(token_dict, EmployeeTokenObject):
|
||||
BuildTypes.filter_attr = list_options
|
||||
results = BuildTypes.filter_all()
|
||||
@@ -33,15 +34,14 @@ class BuildTypesListEventMethods(MethodToEvent):
|
||||
)
|
||||
elif isinstance(token_dict, OccupantTokenObject):
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="You are not authorized to access this endpoint"
|
||||
status_code=403, detail="You are not authorized to access this endpoint"
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="You are not authorized to access this endpoint"
|
||||
status_code=403, detail="You are not authorized to access this endpoint"
|
||||
)
|
||||
|
||||
|
||||
BuildTypesListEventMethod = BuildTypesListEventMethods(
|
||||
action=ActionsSchema(endpoint="/building/types/list")
|
||||
)
|
||||
)
|
||||
|
||||
@@ -180,9 +180,11 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
|
||||
dt = system_arrow.get(last_living_space.expiry_ends)
|
||||
if dt > system_arrow.now():
|
||||
minute_df = int(dt.time().minute) - 10
|
||||
last_living_space.expiry_ends = str(dt.replace(
|
||||
minute=60 - abs(minute_df) if minute_df < 0 else minute_df
|
||||
))
|
||||
last_living_space.expiry_ends = str(
|
||||
dt.replace(
|
||||
minute=60 - abs(minute_df) if minute_df < 0 else minute_df
|
||||
)
|
||||
)
|
||||
last_living_space.save()
|
||||
|
||||
user_module = Modules.filter_one(
|
||||
|
||||
@@ -129,7 +129,7 @@ class CompanyPatchEventMethods(MethodToEvent):
|
||||
cls, company_uu_id: str, data: PatchRecord, token_dict: EmployeeTokenObject
|
||||
):
|
||||
find_one_company = Companies.filter_one(
|
||||
Companies.uu_id==company_uu_id,
|
||||
Companies.uu_id == company_uu_id,
|
||||
).data
|
||||
access_authorized_company = Companies.select_action(
|
||||
duty_id_list=[
|
||||
|
||||
@@ -39,6 +39,7 @@ class DutiesListEventMethods(MethodToEvent):
|
||||
message="List of Duties records",
|
||||
)
|
||||
|
||||
|
||||
class DutiesGetByUUIDEventMethods(MethodToEvent):
|
||||
|
||||
event_type = "GET"
|
||||
|
||||
@@ -195,9 +195,7 @@ class Employee2PeopleEmployEventMethods(MethodToEvent):
|
||||
selected_staff = Staff.filter_one(
|
||||
Staff.uu_id == data.staff_uu_id,
|
||||
).data
|
||||
selected_people = People.filter_one(
|
||||
People.uu_id == data.people_uu_id
|
||||
).data
|
||||
selected_people = People.filter_one(People.uu_id == data.people_uu_id).data
|
||||
if not selected_staff:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
|
||||
@@ -76,9 +76,7 @@ class StaffGetByUUIDEventMethods(MethodToEvent):
|
||||
duties_id = Duties.filter_one(
|
||||
Duties.uu_id == data.duties_uu_id,
|
||||
).data
|
||||
selected_staffs = Staff.filter_all(
|
||||
Staff.duties_id == duties_id.id
|
||||
)
|
||||
selected_staffs = Staff.filter_all(Staff.duties_id == duties_id.id)
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
|
||||
@@ -36,7 +36,6 @@ class DecisionBookListEventMethods(MethodToEvent):
|
||||
):
|
||||
records = []
|
||||
if isinstance(token_dict, EmployeeTokenObject):
|
||||
|
||||
build_id_list_query = Build.select_action(
|
||||
employee_id=token_dict.selected_company.employee_id
|
||||
)
|
||||
@@ -49,12 +48,12 @@ class DecisionBookListEventMethods(MethodToEvent):
|
||||
BuildDecisionBook.filter_attr = list_options
|
||||
records = BuildDecisionBook.filter_all(
|
||||
BuildDecisionBook.build_id.in_([build.id for build in build_id_list]),
|
||||
).data
|
||||
)
|
||||
elif isinstance(token_dict, OccupantTokenObject):
|
||||
BuildDecisionBook.filter_attr = list_options
|
||||
records = BuildDecisionBook.filter_all(
|
||||
BuildDecisionBook.build_id == token_dict.selected_occupant.build_id,
|
||||
).data
|
||||
)
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
message="DecisionBook are listed successfully",
|
||||
@@ -154,7 +153,9 @@ class DecisionBookCreateEventMethods(MethodToEvent):
|
||||
int(decision_period_date.date().month),
|
||||
int(decision_period_date.date().day),
|
||||
)
|
||||
data_dict["expiry_ends"] = str(data_dict["expiry_starts"].shift(years=1, days=-1))
|
||||
data_dict["expiry_ends"] = str(
|
||||
data_dict["expiry_starts"].shift(years=1, days=-1)
|
||||
)
|
||||
data_dict["expiry_starts"] = str(data_dict["expiry_starts"])
|
||||
build_decision_book = BuildDecisionBook.find_or_create(**data_dict)
|
||||
build_decision_book.save()
|
||||
|
||||
@@ -25,6 +25,7 @@ from api_library.date_time_actions.date_functions import system_arrow, client_ar
|
||||
|
||||
from api_validations.validations_request import (
|
||||
InsertBuildDecisionBookItems,
|
||||
ListOptions,
|
||||
ListDecisionBook,
|
||||
)
|
||||
|
||||
@@ -39,7 +40,7 @@ class DecisionBookDecisionBookItemsListEventMethods(MethodToEvent):
|
||||
@classmethod
|
||||
def building_decision_book_items_list(
|
||||
cls,
|
||||
data: ListDecisionBook,
|
||||
data: ListOptions,
|
||||
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
decision_book = BuildDecisionBook.filter_one(
|
||||
@@ -141,7 +142,7 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
|
||||
payment_amount = -1 * (
|
||||
abs(payment_amount) + (50 - float(abs(payment_amount)) % 50)
|
||||
)
|
||||
BuildDecisionBookPayments.create(
|
||||
created_book_payment = BuildDecisionBookPayments.find_or_create(
|
||||
build_parts_id=build_part_single.id,
|
||||
build_parts_uu_id=str(build_part_single.uu_id),
|
||||
payment_amount=payment_amount,
|
||||
@@ -153,6 +154,7 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
|
||||
period_time=f"{local_date.year}-{str(local_date.month).zfill(2)}",
|
||||
**book_payment_dict,
|
||||
)
|
||||
created_book_payment.save_and_confirm()
|
||||
local_date = local_date.shift(days=2)
|
||||
part_key = str(build_part_single.due_part_key).upper()
|
||||
if part_key not in payment_return_dict:
|
||||
@@ -181,7 +183,6 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
|
||||
payment_plan_time_periods=str(data_info_type.key),
|
||||
build_decision_book_item_id=decision_book_item.id,
|
||||
build_decision_book_item_uu_id=str(decision_book_item.uu_id),
|
||||
is_confirmed=True,
|
||||
currency=currency,
|
||||
)
|
||||
payment_types = ApiEnumDropdown.get_debit_search(search_debit="DT-D")
|
||||
@@ -235,7 +236,7 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
|
||||
BuildParts.part_no == 0,
|
||||
).data
|
||||
occupant_man = OccupantTypes.filter_by_one(
|
||||
occupant_code="MT-VPR", occupant_category_type="MT"
|
||||
system=True, occupant_code="MT-VPR", occupant_category_type="MT"
|
||||
).data
|
||||
manager_living_space = BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.build_parts_id == management_room.id,
|
||||
@@ -270,7 +271,7 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
|
||||
f"is assigned to {occupant_man.occupant_description}"
|
||||
)
|
||||
project_lead = ApiEnumDropdown.filter_by_one(
|
||||
key="PTT-LDR", enum_class="ProjectTeamTypes"
|
||||
system=True, key="PTT-LDR", enum_class="ProjectTeamTypes"
|
||||
).data
|
||||
project_person = BuildDecisionBookProjectPerson.find_or_create(
|
||||
build_decision_book_project_id=book_project_created.id,
|
||||
@@ -281,12 +282,12 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
|
||||
project_team_type_uu_id=str(project_lead.uu_id),
|
||||
)
|
||||
BuildDecisionBookProjects.save()
|
||||
return
|
||||
return book_project_created
|
||||
|
||||
elif data_info_type.key == "BDT-SF":
|
||||
elif data_info_type.key == "BDT-S":
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="BDT-SF is not implemented yet. Check info type and try again",
|
||||
detail="BDT-S is not implemented yet. Check info type and try again",
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
@@ -309,7 +310,7 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
|
||||
elif isinstance(token_dict, OccupantTokenObject):
|
||||
data_dict = data.dump()
|
||||
occupant_wrt = OccupantTypes.filter_by_one(
|
||||
occupant_code="MT-WRT", occupant_category_type="MT"
|
||||
system=True, occupant_code="MT-WRT", occupant_category_type="MT"
|
||||
).data
|
||||
|
||||
if token_dict.selected_occupant.occupant_type_id != occupant_wrt.id:
|
||||
@@ -337,30 +338,29 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
|
||||
data_dict["build_decision_book_uu_id"] = str(decision_book.uu_id)
|
||||
data_dict["is_confirmed"] = True
|
||||
|
||||
data_info_types, data_info_type = ApiEnumDropdown.due_type_search(), None
|
||||
data_info_type = ApiEnumDropdown.filter_by_one(
|
||||
system=True, enum_class="BuildDuesTypes", key="BDT-I",
|
||||
).data
|
||||
data_info_types = ApiEnumDropdown.due_type_search()
|
||||
for info_type in data_info_types:
|
||||
if str(info_type.uu_id) == data_dict["info_type_uu_id"]:
|
||||
data_info_type = info_type
|
||||
break
|
||||
if not data_info_type:
|
||||
|
||||
row_is_debit = str(data_info_type.key).upper() in ["BDT-A", "BDT-D"]
|
||||
row_is_project = str(data_info_type.key).upper() in ["BDT-R", "BDT-L", "BDT-S"]
|
||||
debit_dates_required = not data_dict["debit_start_date"] or not data_dict["debit_end_date"]
|
||||
if any([row_is_debit, row_is_project]) and debit_dates_required:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Info Type is not valid. Check info type and try again",
|
||||
detail="Debit Start Date and Debit End Date is required for this payment type. "
|
||||
"Check debit start date and debit end date and try again",
|
||||
)
|
||||
|
||||
if str(data_info_type.key).upper() in ["BDT-A", "BDT-R", "BDT-L", "BDT-SF"]:
|
||||
if not data_dict["debit_start_date"] or not data_dict["debit_end_date"]:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Debit Start Date and Debit End Date is required for this payment type. "
|
||||
"Check debit start date and debit end date and try again",
|
||||
)
|
||||
|
||||
data_dict["info_type_id"] = data_info_type.id
|
||||
data_dict["info_type_uu_id"] = str(data_info_type.uu_id)
|
||||
unit_price, unit_type = float(data_dict["unit_price"]), str(
|
||||
data_dict["unit_type"]
|
||||
)
|
||||
unit_price, unit_type = float(data_dict["unit_price"]), str(data_dict["unit_type"])
|
||||
|
||||
debit_start_date, debit_end_date = (
|
||||
data_dict["debit_start_date"],
|
||||
data_dict["debit_end_date"],
|
||||
@@ -376,58 +376,49 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
|
||||
data_dict["currency"],
|
||||
)
|
||||
|
||||
if new_decision_book_item := BuildDecisionBookItems.find_or_create(
|
||||
new_decision_book_item = BuildDecisionBookItems.find_or_create(
|
||||
**data_dict
|
||||
)
|
||||
if created_payment_records_dict := cls.create_payment_records_for_each_build_part(
|
||||
data_info_type=data_info_type,
|
||||
build_id=decision_book.build_id,
|
||||
unit_price=unit_price,
|
||||
unit_type=unit_type.upper(),
|
||||
decision_book=decision_book,
|
||||
decision_book_item=new_decision_book_item,
|
||||
unit_price_is_fixed=data.unit_price_is_fixed,
|
||||
debit_start_date=debit_start_date,
|
||||
debit_end_date=debit_end_date,
|
||||
currency=currency,
|
||||
):
|
||||
if new_decision_book_item.is_found:
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_200_OK,
|
||||
content=dict(
|
||||
message=f"Decision Book Item is already exist for given Decision Book UUID {decision_book.uu_id}",
|
||||
completed=True,
|
||||
data=new_decision_book_item.get_dict(),
|
||||
),
|
||||
)
|
||||
if created_payment_records_dict := cls.create_payment_records_for_each_build_part(
|
||||
data_info_type=data_info_type,
|
||||
build_id=decision_book.build_id,
|
||||
unit_price=unit_price,
|
||||
unit_type=unit_type.upper(),
|
||||
decision_book=decision_book,
|
||||
decision_book_item=new_decision_book_item,
|
||||
unit_price_is_fixed=data.unit_price_is_fixed,
|
||||
debit_start_date=debit_start_date,
|
||||
debit_end_date=debit_end_date,
|
||||
currency=currency,
|
||||
):
|
||||
if data_info_type.key == "BDT-A" or data_info_type.key == "BDT-D":
|
||||
if data_info_type.key == "BDT-D":
|
||||
item_comment = "Regular Payment Plan : "
|
||||
else:
|
||||
item_comment = "Additional Payment Plan : "
|
||||
for key, value in dict(
|
||||
sorted(
|
||||
created_payment_records_dict.items(),
|
||||
key=lambda x: x[1],
|
||||
reverse=True,
|
||||
)
|
||||
).items():
|
||||
item_comment += f" {key} | {abs(float(value))} {currency}, "
|
||||
item_comment = item_comment[:-2]
|
||||
new_decision_book_item.update(item_comment=item_comment)
|
||||
new_decision_book_item.update(is_payment_created=True)
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_200_OK,
|
||||
content=dict(
|
||||
message=f"Decision Book Item has created for given Decision Book UUID {decision_book.uu_id}",
|
||||
completed=True,
|
||||
data=new_decision_book_item.get_dict(),
|
||||
),
|
||||
)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Decision Book Item is not created. Check info type and info no and try again. Unique constraint index is implemented for info type and info no",
|
||||
)
|
||||
if row_is_debit:
|
||||
if data_info_type.key == "BDT-D":
|
||||
item_comment = "Regular Payment Plan : "
|
||||
else:
|
||||
item_comment = "Additional Payment Plan : "
|
||||
for key, value in dict(
|
||||
sorted(
|
||||
created_payment_records_dict.items(),
|
||||
key=lambda x: x[1],
|
||||
reverse=True,
|
||||
)
|
||||
).items():
|
||||
item_comment += f" {key} | {abs(float(value))} {currency}, "
|
||||
item_comment = item_comment[:-2]
|
||||
new_decision_book_item.update(item_comment=item_comment)
|
||||
new_decision_book_item.update(is_payment_created=True)
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_200_OK,
|
||||
content=dict(
|
||||
message=f"Decision Book Item has created for given Decision Book UUID {decision_book.uu_id}",
|
||||
completed=True,
|
||||
data=new_decision_book_item.get_dict(),
|
||||
),
|
||||
)
|
||||
# raise HTTPException(
|
||||
# status_code=status.HTTP_400_BAD_REQUEST,
|
||||
# detail="Decision Book Item is not created. Check info type and info no and try again. Unique constraint index is implemented for info type and info no",
|
||||
# )
|
||||
|
||||
|
||||
class DecisionBookDecisionBookItemsUpdateEventMethods(MethodToEvent):
|
||||
|
||||
@@ -70,8 +70,10 @@ class DecisionBookPersonAddEventMethods(MethodToEvent):
|
||||
detail=f"No Decision Book is match with given UUID {data.build_decision_book_uu_id}",
|
||||
)
|
||||
manager_occupant_type = OccupantTypes.filter_by_one(
|
||||
occupant_code="BU-MNG", occupant_category_type="BU"
|
||||
).get(1)
|
||||
system=True,
|
||||
occupant_code="BU-MNG",
|
||||
occupant_category_type="BU"
|
||||
).data
|
||||
if (
|
||||
not manager_occupant_type.uu_id
|
||||
== token_dict.selected_occupant.occupant_type_uu_id
|
||||
@@ -82,9 +84,10 @@ class DecisionBookPersonAddEventMethods(MethodToEvent):
|
||||
)
|
||||
|
||||
assign_occupant_type = OccupantTypes.filter_by_one(
|
||||
system=True,
|
||||
uu_id=data.occupant_type_uu_id,
|
||||
occupant_category_type="MT",
|
||||
).get(1)
|
||||
).data
|
||||
if not assign_occupant_type:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -95,9 +98,7 @@ class DecisionBookPersonAddEventMethods(MethodToEvent):
|
||||
BuildDecisionBookPerson.token == data.token,
|
||||
BuildDecisionBookPerson.build_decision_book_uu_id
|
||||
== data.build_decision_book_uu_id,
|
||||
BuildDecisionBookPerson.is_confirmed == True,
|
||||
BuildDecisionBookPerson.active == True,
|
||||
).get(1)
|
||||
).data
|
||||
if not manger_book_person:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -107,7 +108,7 @@ class DecisionBookPersonAddEventMethods(MethodToEvent):
|
||||
BuildDecisionBookInvitations.id == manger_book_person.invite_id,
|
||||
BuildDecisionBookInvitations.build_id
|
||||
== token_dict.selected_occupant.build_id,
|
||||
).get(1)
|
||||
).data
|
||||
if not book_invite:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -116,9 +117,7 @@ class DecisionBookPersonAddEventMethods(MethodToEvent):
|
||||
selected_book_person = BuildDecisionBookPerson.filter_one(
|
||||
BuildDecisionBookPerson.invite_id == book_invite.id,
|
||||
BuildDecisionBookPerson.person_uu_id == data.person_uu_id,
|
||||
BuildDecisionBookPerson.is_confirmed == True,
|
||||
BuildDecisionBookPerson.active == True,
|
||||
).get(1)
|
||||
).data
|
||||
if not selected_book_person:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -173,12 +172,10 @@ class DecisionBookPersonAttendEventMethods(MethodToEvent):
|
||||
detail="Employee cannot create decision book invitations",
|
||||
)
|
||||
|
||||
token_user = Users.filter_one(Users.id == token_dict.user_id).get(1)
|
||||
token_user = Users.filter_one(Users.id == token_dict.user_id).data
|
||||
invitation_person = BuildDecisionBookPerson.filter_one(
|
||||
BuildDecisionBookPerson.token == data.token,
|
||||
BuildDecisionBookPerson.active == True,
|
||||
BuildDecisionBookPerson.is_confirmed == True,
|
||||
).get(1)
|
||||
).data
|
||||
if not invitation_person:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -197,8 +194,7 @@ class DecisionBookPersonAttendEventMethods(MethodToEvent):
|
||||
BuildDecisionBookInvitations.id == invitation_person.invite_id,
|
||||
BuildDecisionBookInvitations.build_id
|
||||
== token_dict.selected_occupant.build_id,
|
||||
BuildDecisionBookInvitations.active == True,
|
||||
).get(1)
|
||||
).data
|
||||
if not invitation:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -246,12 +242,10 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
|
||||
BuildDecisionBookPerson.token == data.token,
|
||||
BuildDecisionBookPerson.build_living_space_id
|
||||
== token_dict.selected_occupant.living_space_id,
|
||||
BuildDecisionBookPerson.active == True,
|
||||
BuildDecisionBookPerson.is_confirmed == True,
|
||||
).get(1)
|
||||
).data
|
||||
manager_occupant_type = OccupantTypes.filter_by_one(
|
||||
occupant_code="BU-MNG", occupant_category_type="BU"
|
||||
).get(1)
|
||||
system=True, occupant_code="BU-MNG", occupant_category_type="BU"
|
||||
).data
|
||||
book_person_manager.check_occupant_type(manager_occupant_type)
|
||||
|
||||
# supervisor_occupant_type = OccupantTypes.find_or_abort(occupant_code="BU-SPV", occupant_category_type="BU")
|
||||
@@ -261,8 +255,7 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
|
||||
BuildDecisionBookInvitations.id == book_person_manager.invite_id,
|
||||
BuildDecisionBookInvitations.build_id
|
||||
== token_dict.selected_occupant.build_id,
|
||||
BuildDecisionBookInvitations.active == True,
|
||||
).get(1)
|
||||
).data
|
||||
if not invitation:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -270,8 +263,8 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
|
||||
)
|
||||
|
||||
assign_occupant_type = OccupantTypes.filter_by_one(
|
||||
uu_id=data.occupant_type_uu_id
|
||||
).get(1)
|
||||
system=True, uu_id=data.occupant_type_uu_id,
|
||||
).data
|
||||
if not assign_occupant_type:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -286,7 +279,7 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
|
||||
BuildLivingSpace.build_parts_id.in_(
|
||||
[build.id for build in build_parts_of_token]
|
||||
),
|
||||
).get(1)
|
||||
).data
|
||||
if not selected_living_space:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -298,35 +291,31 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
|
||||
BuildDecisionBookPerson.build_living_space_id
|
||||
== selected_living_space.id,
|
||||
BuildDecisionBookPerson.invite_id == invitation.id,
|
||||
BuildDecisionBookPerson.active == True,
|
||||
).get(1)
|
||||
).data
|
||||
)
|
||||
if not book_person_to_assign:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=f"Person not found in the invitation list. Please check person uuid: {data.person_uu_id}",
|
||||
detail=f"Person not found in the invitation list. Please check person uuid: {data.build_living_space_uu_id}",
|
||||
)
|
||||
if not book_person_to_assign.is_attending:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=f"Person is declined the invitation. This person is not attending the meeting. "
|
||||
f"Please check person uuid: {data.person_uu_id}. Invite UUID: {invitation.uu_id}",
|
||||
f"Please check person uuid: {data.build_living_space_uu_id}. Invite UUID: {invitation.uu_id}",
|
||||
)
|
||||
|
||||
if assign_occupant_type.occupant_code in ("MT-PRS", "MT-WRT"):
|
||||
occupant_type_unique = OccupantTypes.filter_by_one(
|
||||
system=True,
|
||||
occupant_code=assign_occupant_type.occupant_code,
|
||||
occupant_category_type="MT",
|
||||
).get(1)
|
||||
).data
|
||||
if assigned_book_person_occupant := BuildDecisionBookPersonOccupants.filter_one(
|
||||
BuildDecisionBookPersonOccupants.invite_id == invitation.id,
|
||||
BuildDecisionBookPersonOccupants.occupant_type_id
|
||||
== occupant_type_unique.id,
|
||||
BuildDecisionBookPersonOccupants.active == True,
|
||||
BuildDecisionBookPersonOccupants.is_confirmed == True,
|
||||
).get(
|
||||
1
|
||||
):
|
||||
).data:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=f"Only one person can be assigned to {assign_occupant_type.occupant_code} type"
|
||||
@@ -338,8 +327,6 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
|
||||
BuildDecisionBookPersonOccupants.invite_id == invitation.id,
|
||||
BuildDecisionBookPersonOccupants.occupant_type_id
|
||||
== manager_occupant_type.id,
|
||||
BuildDecisionBookPersonOccupants.active == True,
|
||||
BuildDecisionBookPersonOccupants.is_confirmed == True,
|
||||
)
|
||||
person_occupant_manager.query.delete()
|
||||
|
||||
|
||||
@@ -63,8 +63,8 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
)
|
||||
# Check token posses the occupant type of Build Manager
|
||||
occupant_manager = OccupantTypes.filter_by_one(
|
||||
occupant_category_type="BU", occupant_code="BU-MNG"
|
||||
).get(1)
|
||||
system=True, occupant_category_type="BU", occupant_code="BU-MNG"
|
||||
).data
|
||||
if not token_dict.selected_occupant.occupant_type_id == occupant_manager.id:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
@@ -75,8 +75,7 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
decision_book = BuildDecisionBook.filter_one(
|
||||
BuildDecisionBook.uu_id == data.build_decision_book_uu_id,
|
||||
BuildDecisionBook.build_id == token_dict.selected_occupant.build_id,
|
||||
BuildDecisionBook.active == True,
|
||||
).get(1)
|
||||
).data
|
||||
if not decision_book:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -84,22 +83,12 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
)
|
||||
occupant_building = Build.filter_one(
|
||||
Build.id == token_dict.selected_occupant.build_id
|
||||
).get(1)
|
||||
|
||||
# Check meeting type is valid
|
||||
meeting_type = ApiEnumDropdown.filter_by_one(
|
||||
enum_class="MeetingTypes",
|
||||
).get(1)
|
||||
if not meeting_type:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Meeting type not found",
|
||||
)
|
||||
).data
|
||||
|
||||
# Check planned decision book date is valid
|
||||
if (
|
||||
not system_arrow.get(data.planned_date).date()
|
||||
>= system_arrow.shift(days=1).date()
|
||||
>= system_arrow.now().shift(days=1).date()
|
||||
):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
@@ -107,32 +96,21 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
)
|
||||
|
||||
# Create an invitation for specific invitation type to start invite sending process
|
||||
planned_date_expires = (
|
||||
str(system_arrow.get(data.planned_date).shift(days=15).date()),
|
||||
)
|
||||
planned_date_expires = str(system_arrow.get(data.planned_date).shift(days=15).date())
|
||||
book_invitation = BuildDecisionBookInvitations.find_or_create(
|
||||
build_id=token_dict.selected_occupant.build_id,
|
||||
build_uu_id=token_dict.selected_occupant.build_uuid,
|
||||
decision_book_id=decision_book.id,
|
||||
decision_book_uu_id=str(decision_book.uu_id),
|
||||
invitation_type=meeting_type.key,
|
||||
invitation_type=str(decision_book.decision_type),
|
||||
living_part_count=occupant_building.livable_part_count,
|
||||
living_part_percentage=0.51,
|
||||
message=data.message,
|
||||
planned_date=data.planned_date,
|
||||
planned_date=str(system_arrow.get(data.planned_date)),
|
||||
planned_date_expires=planned_date_expires,
|
||||
expiry_ends=str(system_arrow.get(data.planned_date).shift(days=15).date()),
|
||||
is_confirmed=True,
|
||||
)
|
||||
if book_invitation.is_found:
|
||||
detail_message = (
|
||||
f"Invitation with: {str(book_invitation.planned_date)} already exists"
|
||||
f" for {book_invitation.invitation_type}"
|
||||
)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=detail_message,
|
||||
)
|
||||
book_invitation.save_and_confirm()
|
||||
|
||||
# Get all the parts of the building that is occupant in token
|
||||
build_parts = BuildParts.filter_all(
|
||||
@@ -164,12 +142,12 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
)
|
||||
|
||||
# Send invitation to all the users as attend and update the manager as build manager
|
||||
attendance_occupant_type = OccupantTypes.find_or_abort(
|
||||
occupant_code="MT-ATT", occupant_category_type="MT"
|
||||
)
|
||||
manager_occupant_type = OccupantTypes.find_or_abort(
|
||||
occupant_code="BU-MNG", occupant_category_type="BU"
|
||||
)
|
||||
attendance_occupant_type = OccupantTypes.filter_by_one(
|
||||
system=True, occupant_code="MT-ATT", occupant_category_type="MT"
|
||||
).data
|
||||
manager_occupant_type = OccupantTypes.filter_by_one(
|
||||
system=True, occupant_code="BU-MNG", occupant_category_type="BU"
|
||||
).data
|
||||
|
||||
build_decision_book_person_dict = dict(
|
||||
build_decision_book_id=decision_book.id,
|
||||
@@ -179,7 +157,6 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
send_date=str(system_arrow.now().date()),
|
||||
expiry_starts=decision_book.expiry_starts,
|
||||
expiry_ends=decision_book.expiry_ends,
|
||||
is_confirmed=True,
|
||||
)
|
||||
# Check if the invitation is already created at database
|
||||
for build_living_spaces_user in build_living_spaces_people:
|
||||
@@ -201,12 +178,12 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
person_id=build_living_spaces_user.person_id,
|
||||
token=Users.generate_token(40),
|
||||
)
|
||||
invitations_person.save_and_confirm()
|
||||
|
||||
invitations_person.add_occupant_type(occupant_type=attendance_occupant_type)
|
||||
if invitations_person and not invitations_person.is_found:
|
||||
if invitations_person:
|
||||
print(f'"{invitations_person.token}",')
|
||||
spaces_user = Users.filter_one(
|
||||
Users.active == True,
|
||||
Users.is_confirmed == True,
|
||||
Users.person_id == build_living_spaces_user.person_id,
|
||||
).data
|
||||
# print(
|
||||
@@ -222,18 +199,22 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
BuildDecisionBookPerson.invite_id == book_invitation.id,
|
||||
BuildDecisionBookPerson.build_living_space_id.in_(
|
||||
[
|
||||
manager_living_space.id
|
||||
for manager_living_space in manager_living_spaces.data
|
||||
manager_living_space.id for manager_living_space in manager_living_spaces.data
|
||||
]
|
||||
),
|
||||
system=True,
|
||||
)
|
||||
manager_people_occupants = BuildDecisionBookPersonOccupants.filter_all(
|
||||
BuildDecisionBookPersonOccupants.build_decision_book_person_id
|
||||
== manager_people.get(1).id,
|
||||
|
||||
system=True,
|
||||
)
|
||||
manager_people_occupants.query.delete()
|
||||
manager_people.query.delete()
|
||||
if manager_people_occupants.count:
|
||||
manager_people_occupants.query.delete()
|
||||
BuildDecisionBookPersonOccupants.save()
|
||||
if manager_people.count:
|
||||
manager_people.query.delete()
|
||||
BuildDecisionBookPerson.save()
|
||||
|
||||
if book_person_manager := BuildDecisionBookPerson.find_or_create(
|
||||
**build_decision_book_person_dict,
|
||||
@@ -244,6 +225,7 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
person_id=token_dict.person_id,
|
||||
token=Users.generate_token(40),
|
||||
):
|
||||
book_person_manager.save_and_confirm()
|
||||
book_person_manager.add_occupant_type(occupant_type=manager_occupant_type)
|
||||
print(f"Manager Token : {book_person_manager.token}")
|
||||
BuildDecisionBookPerson.save()
|
||||
|
||||
@@ -32,9 +32,7 @@ class ModulesBindOccupantEventMethods(MethodToEvent):
|
||||
living_space = BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.id == build_living_space_id,
|
||||
).data
|
||||
modules = Modules.filter_one(
|
||||
Modules.id == modules_id
|
||||
).data
|
||||
modules = Modules.filter_one(Modules.id == modules_id).data
|
||||
|
||||
if not living_space or not modules:
|
||||
print(f"Giving living Space or Modules: {modules.module_name} not found")
|
||||
@@ -43,7 +41,9 @@ class ModulesBindOccupantEventMethods(MethodToEvent):
|
||||
if expires_at:
|
||||
service_build_dict["expires_at"] = str(system_arrow.get(expires_at))
|
||||
else:
|
||||
service_build_dict["expires_at"] = str(system_arrow.get(living_space.expiry_ends))
|
||||
service_build_dict["expires_at"] = str(
|
||||
system_arrow.get(living_space.expiry_ends)
|
||||
)
|
||||
|
||||
for service in modules.retrieve_services():
|
||||
ServiceBindOccupantEventMethods.bind_services_occupant_system(
|
||||
|
||||
@@ -35,6 +35,7 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
||||
cls, build_living_space_id: int, service_id: int, expires_at: str = None
|
||||
):
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
|
||||
living_space = BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.id == build_living_space_id,
|
||||
).data
|
||||
@@ -218,10 +219,8 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
||||
)
|
||||
count_row = session_execute.rowcount
|
||||
print(f"{count_row} events are added to employee {employee.uu_id}")
|
||||
Services.save()
|
||||
for service_event in service_events:
|
||||
service_event.is_confirmed = True
|
||||
Service2Events.save()
|
||||
service_event.save_and_confirm()
|
||||
|
||||
@classmethod
|
||||
def bind_services_employee_super_user(
|
||||
|
||||
@@ -45,9 +45,7 @@ class UserListEventMethods(MethodToEvent):
|
||||
people_ids = list_options.query.pop("user_uu_id_list")
|
||||
people_id_list = (
|
||||
user.person_id
|
||||
for user in Users.filter_all(
|
||||
Users.uu_id.in_(people_ids)
|
||||
).data
|
||||
for user in Users.filter_all(Users.uu_id.in_(people_ids)).data
|
||||
)
|
||||
Users.filter_attr = list_options
|
||||
records = Users.filter_all(
|
||||
@@ -80,12 +78,11 @@ class UserCreateEventMethods(MethodToEvent):
|
||||
data: InsertUsers,
|
||||
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
created_user = Users.create_action(create_user=data)
|
||||
created_user.related_company = token_dict.selected_company.company_uu_id
|
||||
created_user = Users.create_action(create_user=data, token_dict=token_dict)
|
||||
domain_via_user = DomainViaUser(
|
||||
**{"user_uu_id": str(created_user.uu_id), "main_domain": "evyos.com.tr"}
|
||||
)
|
||||
created_user.save()
|
||||
created_user.save_and_confirm()
|
||||
mongo_query_identity = MongoQueryIdentity(
|
||||
company_uuid=created_user.related_company,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user