updated
This commit is contained in:
96
test_environment/test_payment.py
Normal file
96
test_environment/test_payment.py
Normal file
@@ -0,0 +1,96 @@
|
||||
import pprint
|
||||
|
||||
import arrow
|
||||
|
||||
from api_library.date_time_actions.date_functions import client_arrow, system_arrow
|
||||
from databases.sql_models.building.decision_book import BuildDecisionBookPayments
|
||||
|
||||
|
||||
def decision_book_payment_list():
|
||||
"""
|
||||
SELECT payment_plan_time_periods, process_date, payment_amount, currency, payment_types_id,
|
||||
payment_types_uu_id, period_time, process_date_y, process_date_m, build_decision_book_item_id,
|
||||
build_decision_book_item_uu_id, decision_book_project_id, decision_book_project_uu_id, build_parts_id,
|
||||
build_parts_uu_id, id, uu_id, ref_id, created_at, updated_at, cryp_uu_id, created_by, created_by_id,
|
||||
updated_by, updated_by_id, confirmed_by, confirmed_by_id, is_confirmed, replication_id, deleted,
|
||||
active, is_notification_send, is_email_send, expiry_starts, expiry_ends, account_records_id,
|
||||
account_records_uu_id FROM public.build_decision_book_payments;
|
||||
"""
|
||||
from sqlalchemy import func, select, union_all, extract, Integer
|
||||
|
||||
build_parts_id, build_decision_book_id = 7, ""
|
||||
payment_types_id_recv, payment_types_id_deb = 46, 45
|
||||
book_payments = BuildDecisionBookPayments.filter_all(
|
||||
BuildDecisionBookPayments.build_parts_id == build_parts_id,
|
||||
BuildDecisionBookPayments.process_date
|
||||
<= system_arrow.find_last_day_of_month(arrow.now()).__str__(),
|
||||
).data
|
||||
is_datetime_is_this_month = lambda x: arrow.get(x).format(
|
||||
"YYYY-MM"
|
||||
) == arrow.now().format("YYYY-MM")
|
||||
|
||||
dict_books, dict_books_monthly = {}, {}
|
||||
for book_payment in book_payments:
|
||||
book_payment: BuildDecisionBookPayments = book_payment
|
||||
if is_datetime_is_this_month(book_payment.process_date):
|
||||
if book_payment.payment_plan_time_periods not in dict_books_monthly:
|
||||
dict_books_monthly[book_payment.payment_plan_time_periods] = {
|
||||
"debt": 0,
|
||||
"recv": 0,
|
||||
"ls": str(book_payment.process_date),
|
||||
}
|
||||
if book_payment.payment_types_id == payment_types_id_deb:
|
||||
dict_books_monthly[book_payment.payment_plan_time_periods][
|
||||
"debt"
|
||||
] += book_payment.payment_amount
|
||||
else:
|
||||
dict_books_monthly[book_payment.payment_plan_time_periods][
|
||||
"recv"
|
||||
] += book_payment.payment_amount
|
||||
if arrow.get(str(book_payment.process_date)) > arrow.get(
|
||||
dict_books_monthly[book_payment.payment_plan_time_periods]["ls"]
|
||||
):
|
||||
dict_books_monthly[book_payment.payment_plan_time_periods]["ls"] = str(
|
||||
book_payment.process_date
|
||||
)
|
||||
dict_books_monthly[book_payment.payment_plan_time_periods]["balance"] = (
|
||||
dict_books_monthly[book_payment.payment_plan_time_periods]["debt"]
|
||||
+ dict_books_monthly[book_payment.payment_plan_time_periods]["recv"]
|
||||
)
|
||||
|
||||
if book_payment.payment_plan_time_periods not in dict_books:
|
||||
dict_books[book_payment.payment_plan_time_periods] = {
|
||||
"debt": 0,
|
||||
"recv": 0,
|
||||
"ls": str(book_payment.process_date),
|
||||
}
|
||||
date_process = dict_books[book_payment.payment_plan_time_periods]["ls"]
|
||||
if arrow.get(str(date_process)) < arrow.get(str(book_payment.process_date)):
|
||||
dict_books[book_payment.payment_plan_time_periods]["ls"] = str(
|
||||
book_payment.process_date
|
||||
)
|
||||
if book_payment.payment_types_id == payment_types_id_deb:
|
||||
dict_books[book_payment.payment_plan_time_periods][
|
||||
"debt"
|
||||
] += book_payment.payment_amount
|
||||
else:
|
||||
dict_books[book_payment.payment_plan_time_periods][
|
||||
"recv"
|
||||
] += book_payment.payment_amount
|
||||
dict_books[book_payment.payment_plan_time_periods]["balance"] = (
|
||||
dict_books[book_payment.payment_plan_time_periods]["debt"]
|
||||
+ dict_books[book_payment.payment_plan_time_periods]["recv"]
|
||||
)
|
||||
|
||||
return dict(
|
||||
Month=[{**item, "type": key} for key, item in dict_books_monthly.items()],
|
||||
Total=[{**item, "type": key} for key, item in dict_books.items()],
|
||||
)
|
||||
|
||||
result = decision_book_payment_list()
|
||||
print('result', result)
|
||||
pprint.pprint(result, indent=2)
|
||||
# for key, val in result.items():
|
||||
# print('key', key)
|
||||
# for item in val:
|
||||
# print(item)
|
||||
Reference in New Issue
Block a user