events updated
This commit is contained in:
@@ -14,7 +14,8 @@ from databases import (
|
||||
AccountRecords,
|
||||
BuildIbans,
|
||||
)
|
||||
from databases.sql_models.building.build import Build
|
||||
from databases.sql_models.building.build import Build, BuildLivingSpace
|
||||
from databases.sql_models.building.decision_book import BuildDecisionBookPayments
|
||||
from databases.sql_models.others.enums import ApiEnumDropdown
|
||||
|
||||
|
||||
@@ -26,6 +27,7 @@ class AccountRecordsListEventMethods(MethodToEvent):
|
||||
|
||||
__event_keys__ = {
|
||||
"7192c2aa-5352-4e36-98b3-dafb7d036a3d": "account_records_list",
|
||||
"208e6273-17ef-44f0-814a-8098f816b63a": "account_records_list_flt_res",
|
||||
}
|
||||
|
||||
@classmethod
|
||||
@@ -46,15 +48,136 @@ class AccountRecordsListEventMethods(MethodToEvent):
|
||||
AccountRecords.filter_attr = list_options
|
||||
records = AccountRecords.filter_all()
|
||||
return AlchemyJsonResponse(
|
||||
completed=True, message="Update Build record", result=records
|
||||
completed=True, message="List Build record", result=records
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def account_records_list_flt_res_or_ten(cls):
|
||||
"""
|
||||
FLT-RES | FLT-TEN | FLT-OWN aidatları görür
|
||||
"""
|
||||
return
|
||||
def account_records_list_flt_res(
|
||||
cls,
|
||||
list_options: ListOptions,
|
||||
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
if not isinstance(token_dict, OccupantTokenObject):
|
||||
raise AccountRecords().raise_http_exception(
|
||||
status_code="HTTP_404_NOT_FOUND",
|
||||
error_case="UNAUTHORIZED",
|
||||
message="Only Occupant can see this data",
|
||||
data={},
|
||||
)
|
||||
|
||||
return_list = []
|
||||
living_space: BuildLivingSpace = BuildLivingSpace.filter_by_one(
|
||||
id=token_dict.selected_occupant.living_space_id
|
||||
).data
|
||||
if not living_space:
|
||||
raise AccountRecords().raise_http_exception(
|
||||
status_code="HTTP_404_NOT_FOUND",
|
||||
error_case="UNAUTHORIZED",
|
||||
message="Living space not found",
|
||||
data={},
|
||||
)
|
||||
|
||||
if not list_options:
|
||||
list_options = ListOptions()
|
||||
|
||||
main_filters = [
|
||||
AccountRecords.living_space_id
|
||||
== token_dict.selected_occupant.living_space_id,
|
||||
BuildDecisionBookPayments.process_date
|
||||
>= str(system_arrow.now().shift(months=-3).date()),
|
||||
BuildDecisionBookPayments.process_date
|
||||
< str(system_arrow.find_last_day_of_month(living_space.expiry_ends)),
|
||||
BuildDecisionBookPayments.process_date
|
||||
>= str(system_arrow.get(living_space.expiry_starts)),
|
||||
BuildDecisionBookPayments.is_confirmed == True,
|
||||
AccountRecords.active == True,
|
||||
]
|
||||
order_type = "desc"
|
||||
if list_options.order_type:
|
||||
order_type = "asc" if list_options.order_type[0] == "a" else "desc"
|
||||
|
||||
order_by_list = BuildDecisionBookPayments.process_date.desc()
|
||||
if list_options.order_field:
|
||||
if list_options.order_field == "process_date":
|
||||
order_by_list = (
|
||||
BuildDecisionBookPayments.process_date.asc()
|
||||
if order_type == "asc"
|
||||
else BuildDecisionBookPayments.process_date.desc()
|
||||
)
|
||||
if list_options.order_field == "bank_date":
|
||||
order_by_list = (
|
||||
AccountRecords.bank_date.desc()
|
||||
if order_type == "asc"
|
||||
else AccountRecords.bank_date.asc()
|
||||
)
|
||||
if list_options.order_field == "currency_value":
|
||||
order_by_list = (
|
||||
AccountRecords.currency_value.desc()
|
||||
if order_type == "asc"
|
||||
else AccountRecords.currency_value.asc()
|
||||
)
|
||||
if list_options.order_field == "process_comment":
|
||||
order_by_list = (
|
||||
AccountRecords.process_comment.desc()
|
||||
if order_type == "asc"
|
||||
else AccountRecords.process_comment.asc()
|
||||
)
|
||||
if list_options.order_field == "payment_amount":
|
||||
order_by_list = (
|
||||
BuildDecisionBookPayments.payment_amount.desc()
|
||||
if order_type == "asc"
|
||||
else BuildDecisionBookPayments.payment_amount.asc()
|
||||
)
|
||||
|
||||
if list_options.query:
|
||||
for key, value in list_options.query.items():
|
||||
if key == "process_date":
|
||||
main_filters.append(BuildDecisionBookPayments.process_date == value)
|
||||
if key == "bank_date":
|
||||
main_filters.append(AccountRecords.bank_date == value)
|
||||
if key == "currency":
|
||||
main_filters.append(BuildDecisionBookPayments.currency == value)
|
||||
if key == "currency_value":
|
||||
main_filters.append(AccountRecords.currency_value == value)
|
||||
if key == "process_comment":
|
||||
main_filters.append(AccountRecords.process_comment == value)
|
||||
if key == "payment_amount":
|
||||
main_filters.append(
|
||||
BuildDecisionBookPayments.payment_amount == value
|
||||
)
|
||||
|
||||
query = (
|
||||
AccountRecords.session.query(
|
||||
BuildDecisionBookPayments.process_date,
|
||||
BuildDecisionBookPayments.payment_amount,
|
||||
BuildDecisionBookPayments.currency,
|
||||
AccountRecords.bank_date,
|
||||
AccountRecords.currency_value,
|
||||
AccountRecords.process_comment,
|
||||
BuildDecisionBookPayments.uu_id,
|
||||
)
|
||||
.join(
|
||||
AccountRecords,
|
||||
AccountRecords.id == BuildDecisionBookPayments.account_records_id,
|
||||
)
|
||||
.filter(*main_filters)
|
||||
).order_by(order_by_list)
|
||||
|
||||
query.limit(list_options.page_size or 5).offset(
|
||||
(list_options.page or 1 - 1) * list_options.page_size or 5
|
||||
)
|
||||
for list_of_values in query.all() or []:
|
||||
return_list.append(
|
||||
{
|
||||
"process_date": list_of_values[0],
|
||||
"payment_amount": list_of_values[1],
|
||||
"currency": list_of_values[2],
|
||||
"bank_date": list_of_values[3],
|
||||
"currency_value": list_of_values[4],
|
||||
"process_comment": list_of_values[5],
|
||||
}
|
||||
)
|
||||
return dict(completed=True, message="List Build record", result=return_list)
|
||||
|
||||
|
||||
class AccountRecordsCreateEventMethods(MethodToEvent):
|
||||
|
||||
Reference in New Issue
Block a user