decision book create update
This commit is contained in:
@@ -27,6 +27,12 @@ from api_events.events.authentication import (
|
||||
AuthenticationForgotPasswordEventMethod,
|
||||
AuthenticationDownloadAvatarEventMethod,
|
||||
)
|
||||
from api_events.events.account.account_records import (
|
||||
AccountRecordsListEventMethod,
|
||||
AccountRecordsCreateEventMethod,
|
||||
AccountRecordsUpdateEventMethod,
|
||||
AccountRecordsPatchEventMethod,
|
||||
)
|
||||
from api_events.events.identity.users import (
|
||||
UserListEventMethod,
|
||||
UserCreateEventMethod,
|
||||
@@ -163,6 +169,10 @@ __all__ = [
|
||||
"AuthenticationRefreshTokenEventMethod",
|
||||
"AuthenticationForgotPasswordEventMethod",
|
||||
"AuthenticationDownloadAvatarEventMethod",
|
||||
"AccountRecordsListEventMethod",
|
||||
"AccountRecordsCreateEventMethod",
|
||||
"AccountRecordsUpdateEventMethod",
|
||||
"AccountRecordsPatchEventMethod",
|
||||
"UserListEventMethod",
|
||||
"UserCreateEventMethod",
|
||||
"UserUpdateEventMethod",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import typing
|
||||
|
||||
from api_library.date_time_actions.date_functions import system_arrow
|
||||
from api_validations.validations_request import (
|
||||
InsertAccountRecord,
|
||||
UpdateAccountRecord,
|
||||
@@ -13,6 +14,8 @@ from databases import (
|
||||
AccountRecords,
|
||||
BuildIbans,
|
||||
)
|
||||
from databases.sql_models.building.build import Build
|
||||
from databases.sql_models.others.enums import ApiEnumDropdown
|
||||
|
||||
|
||||
class AccountRecordsListEventMethods(MethodToEvent):
|
||||
@@ -61,12 +64,11 @@ class AccountRecordsCreateEventMethods(MethodToEvent):
|
||||
data: InsertAccountRecord,
|
||||
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
|
||||
data_dict = data.excluded_dump()
|
||||
if isinstance(token_dict, OccupantTokenObject):
|
||||
build_iban = BuildIbans.filter_one(
|
||||
BuildIbans.iban == data.iban,
|
||||
BuildIbans.company_id
|
||||
== token_dict.selected_occupant.responsible_company_id,
|
||||
BuildIbans.build_id == token_dict.selected_occupant.build_id,
|
||||
).data
|
||||
if not build_iban:
|
||||
BuildIbans.raise_http_exception(
|
||||
@@ -84,23 +86,47 @@ class AccountRecordsCreateEventMethods(MethodToEvent):
|
||||
result=account_record.get_dict(),
|
||||
)
|
||||
elif isinstance(token_dict, EmployeeTokenObject):
|
||||
build_iban = BuildIbans.filter_one(
|
||||
BuildIbans.iban == data.iban,
|
||||
BuildIbans.company_id == token_dict.selected_company.company_id,
|
||||
).data
|
||||
if not build_iban:
|
||||
BuildIbans.raise_http_exception(
|
||||
status_code="HTTP_404_NOT_FOUND",
|
||||
error_case="UNAUTHORIZED",
|
||||
message=f"{data.iban} is not found in company related to your organization",
|
||||
data={
|
||||
"iban": data.iban,
|
||||
},
|
||||
)
|
||||
account_record = AccountRecords.find_or_create(**data.excluded_dump())
|
||||
# Build.pre_query = Build.select_action(
|
||||
# employee_id=token_dict.selected_employee.employee_id,
|
||||
# )
|
||||
# build_ids_list = Build.filter_all(
|
||||
# *Build.valid_record_args(Build),
|
||||
# )
|
||||
# build_iban = BuildIbans.filter_one(
|
||||
# BuildIbans.iban == data.iban,
|
||||
# BuildIbans.build_id.in_([build.id for build in build_ids_list.data]),
|
||||
# ).data
|
||||
# if not build_iban:
|
||||
# BuildIbans.raise_http_exception(
|
||||
# status_code="HTTP_404_NOT_FOUND",
|
||||
# error_case="UNAUTHORIZED",
|
||||
# message=f"{data.iban} is not found in company related to your organization",
|
||||
# data={
|
||||
# "iban": data.iban,
|
||||
# },
|
||||
# )
|
||||
bank_date = system_arrow.get(data.bank_date)
|
||||
data_dict["bank_date_w"] = bank_date.weekday()
|
||||
data_dict["bank_date_m"] = bank_date.month
|
||||
data_dict["bank_date_d"] = bank_date.day
|
||||
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
|
||||
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
|
||||
data_dict["receive_debit"] = debit_type.id
|
||||
data_dict["receive_debit_uu_id"] = str(debit_type.uu_id)
|
||||
|
||||
account_record = AccountRecords.find_or_create(**data_dict)
|
||||
account_record.save()
|
||||
account_record.update(is_confirmed=True)
|
||||
account_record.save()
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
message="Update Build record",
|
||||
message="Create Account record are successful",
|
||||
result=account_record.get_dict(),
|
||||
)
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class BuildListEventMethods(MethodToEvent):
|
||||
Build.filter_attr = list_options
|
||||
records = Build.filter_all(
|
||||
*Build.valid_record_args(Build),
|
||||
).data
|
||||
)
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
message="Building Records are listed",
|
||||
|
||||
@@ -36,7 +36,6 @@ class BuildingBuildPartsListEventMethods(MethodToEvent):
|
||||
build_list_ids = [build.id for build in build_list_query.all()]
|
||||
BuildParts.pre_query = BuildParts.filter_all(
|
||||
BuildParts.build_id.in_(build_list_ids),
|
||||
*BuildParts.valid_record_args(BuildParts),
|
||||
).query
|
||||
BuildParts.filter_attr = list_options
|
||||
records = BuildParts.filter_all(
|
||||
@@ -64,6 +63,8 @@ class BuildingBuildPartsCreateEventMethods(MethodToEvent):
|
||||
):
|
||||
created_build = BuildParts.create_action(data=data, token=token_dict)
|
||||
created_build.save()
|
||||
created_build.update(is_confirmed=True)
|
||||
created_build.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
|
||||
@@ -137,7 +137,7 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
|
||||
error_case="UNAUTHORIZED",
|
||||
message=f"{data.build_parts_uu_id} - Build Part is not found in database. Check build part uu_id",
|
||||
data={
|
||||
"life_person_uu_id": data.life_person_uu_id,
|
||||
"build_parts_uu_id": data.build_parts_uu_id,
|
||||
},
|
||||
)
|
||||
life_person = People.filter_one(
|
||||
@@ -148,9 +148,9 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
|
||||
BuildLivingSpace.raise_http_exception(
|
||||
status_code="HTTP_404_NOT_FOUND",
|
||||
error_case="UNAUTHORIZED",
|
||||
message=f"{data.life_person_uu_id} - Living Person is not found in database.",
|
||||
message=f"{data.person_uu_id} - Living Person is not found in database.",
|
||||
data={
|
||||
"life_person_uu_id": data.life_person_uu_id,
|
||||
"person_uu_id": data.person_uu_id,
|
||||
},
|
||||
)
|
||||
occupant_type = OccupantTypes.filter_by_one(uu_id=data.occupant_type_uu_id).data
|
||||
|
||||
@@ -84,8 +84,8 @@ class DecisionBookCreateEventMethods(MethodToEvent):
|
||||
)
|
||||
build = Build.filter_one(
|
||||
Build.uu_id == data.build_uu_id,
|
||||
Build.active == True,
|
||||
).get(1)
|
||||
*Build.valid_record_args(Build),
|
||||
).data
|
||||
if not build:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -102,7 +102,7 @@ class DecisionBookCreateEventMethods(MethodToEvent):
|
||||
company = Companies.filter_one(
|
||||
Companies.uu_id == data.resp_company_uu_id,
|
||||
*Companies.valid_record_args(Companies),
|
||||
).get(1)
|
||||
).data
|
||||
if not company:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -144,11 +144,11 @@ class DecisionBookCreateEventMethods(MethodToEvent):
|
||||
occupant_build = Build.filter_one(
|
||||
Build.id == token_dict.selected_occupant.build_id,
|
||||
*Build.valid_record_args(Build),
|
||||
).get(1)
|
||||
).data
|
||||
occupant_company = Companies.filter_one(
|
||||
Companies.id == token_dict.selected_occupant.responsible_company_id,
|
||||
*Companies.valid_record_args(Companies),
|
||||
).get(1)
|
||||
).data
|
||||
data_dict["build_id"] = occupant_build.id
|
||||
data_dict["build_uu_id"] = str(occupant_build.uu_id)
|
||||
data_dict["resp_company_id"] = occupant_company.id
|
||||
@@ -160,12 +160,12 @@ 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)
|
||||
BuildDecisionBook.save()
|
||||
build_decision_book.save()
|
||||
build_decision_book.update(is_confirmed=True)
|
||||
build_decision_book.save()
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_200_OK,
|
||||
content=dict(
|
||||
|
||||
@@ -41,7 +41,7 @@ class PeopleListEventMethods(MethodToEvent):
|
||||
People.filter_attr = list_options
|
||||
records = People.filter_all(
|
||||
*People.valid_record_args(People),
|
||||
).data
|
||||
)
|
||||
elif isinstance(token_dict, OccupantTokenObject):
|
||||
related_users = Users.filter_all(
|
||||
Users.related_company
|
||||
@@ -54,7 +54,7 @@ class PeopleListEventMethods(MethodToEvent):
|
||||
People.filter_attr = list_options
|
||||
records = People.filter_all(
|
||||
*People.valid_record_args(People),
|
||||
).data
|
||||
)
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
message="People are listed successfully",
|
||||
|
||||
Reference in New Issue
Block a user