services are checked

This commit is contained in:
2024-11-08 17:14:02 +03:00
parent a5b1e0b2f4
commit c5b771e5cb
82 changed files with 1720 additions and 869 deletions

View File

@@ -109,15 +109,15 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
@classmethod
def iterate_over_build_parts(
cls,
build_parts_list,
payment_types,
local_date,
end_date,
unit_price,
unit_type,
book_payment_dict,
unit_price_is_fixed
cls,
build_parts_list,
payment_types,
local_date,
end_date,
unit_price,
unit_type,
book_payment_dict,
unit_price_is_fixed,
):
start_date, payment_return_dict = local_date, {}
for build_part_single in build_parts_list:
@@ -129,7 +129,9 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
unit_amount = str(build_part_single.due_part_key).replace(" ", "")
unit_amount = unit_amount.replace(str(unit_type).upper(), "")
payment_amount = abs(unit_price * float(unit_amount)) * -1
payment_amount = -1 * (abs(payment_amount) + (50 - float(abs(payment_amount)) % 50))
payment_amount = -1 * (
abs(payment_amount) + (50 - float(abs(payment_amount)) % 50)
)
BuildDecisionBookPayments.create(
build_parts_id=build_part_single.id,
build_parts_uu_id=str(build_part_single.uu_id),
@@ -140,7 +142,7 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
process_date_m=int(local_date.month),
process_date_y=int(local_date.year),
period_time=f"{local_date.year}-{str(local_date.month).zfill(2)}",
**book_payment_dict
**book_payment_dict,
)
local_date = local_date.shift(days=2)
part_key = str(build_part_single.due_part_key).upper()
@@ -151,17 +153,17 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
@classmethod
def create_payment_records_for_each_build_part(
cls,
data_info_type,
build_id,
unit_price,
unit_type,
decision_book,
decision_book_item,
unit_price_is_fixed,
currency,
debit_start_date: str = None,
debit_end_date: str = None,
cls,
data_info_type,
build_id,
unit_price,
unit_type,
decision_book,
decision_book_item,
unit_price_is_fixed,
currency,
debit_start_date: str = None,
debit_end_date: str = None,
):
build_parts_list = BuildParts.filter_active(
BuildParts.human_livable == True,
@@ -176,8 +178,12 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
)
payment_types = ApiEnumDropdown.get_debit_search(search_debit="DT-D")
if data_info_type.key == "BDT-D":
local_date = system_arrow.get(system_arrow.get(decision_book.expiry_starts).date())
end_date = system_arrow.get(system_arrow.get(decision_book.expiry_ends).date())
local_date = system_arrow.get(
system_arrow.get(decision_book.expiry_starts).date()
)
end_date = system_arrow.get(
system_arrow.get(decision_book.expiry_ends).date()
)
cls.iterate_over_build_parts(
build_parts_list=build_parts_list.data,
payment_types=payment_types,
@@ -212,8 +218,9 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
meeting_date = system_arrow.get(decision_book.meeting_date).date()
already_book_projects = BuildDecisionBookProjects.filter_all(
BuildDecisionBookProjects.build_decision_book_id==decision_book.id,
BuildDecisionBookProjects.project_type==f"{decision_book.decision_type}_{data_info_type.key}",
BuildDecisionBookProjects.build_decision_book_id == decision_book.id,
BuildDecisionBookProjects.project_type
== f"{decision_book.decision_type}_{data_info_type.key}",
)
management_room = BuildParts.find_one(
build_id=build_id, part_no=0, active=True, is_confirmed=True
@@ -222,7 +229,8 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
occupant_code="MT-VPR", occupant_category_type="MT"
)
manager_living_space = BuildLivingSpace.filter_by_active(
build_parts_id=management_room.id, occupant_type=occupant_man.id,
build_parts_id=management_room.id,
occupant_type=occupant_man.id,
)
if not manager_living_space.data:
raise HTTPException(
@@ -245,10 +253,12 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
project_response_living_space_id=manager_living_space.id,
project_response_living_space_uu_id=str(manager_living_space.uu_id),
)
book_project_created = BuildDecisionBookProjects.find_or_create(**book_project_dict)
book_project_created = BuildDecisionBookProjects.find_or_create(
**book_project_dict
)
decision_book_item.update(
item_comment=f"{book_project_created.project_no}_{book_project_created.project_name} "
f"is assigned to {occupant_man.occupant_description}"
f"is assigned to {occupant_man.occupant_description}"
)
project_lead = ApiEnumDropdown.find_one(
key="PTT-LDR", enum_class="ProjectTeamTypes"
@@ -332,13 +342,18 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
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",
"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"])
debit_start_date, debit_end_date = data_dict["debit_start_date"], data_dict["debit_end_date"]
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"],
)
currency = data_dict["currency"]
del (
data_dict["token"],
@@ -347,10 +362,12 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
data_dict["unit_price_is_fixed"],
data_dict["debit_start_date"],
data_dict["debit_end_date"],
data_dict["currency"]
data_dict["currency"],
)
if new_decision_book_item := BuildDecisionBookItems.find_or_create(**data_dict):
if new_decision_book_item := BuildDecisionBookItems.find_or_create(
**data_dict
):
if new_decision_book_item.is_found:
return JSONResponse(
status_code=status.HTTP_200_OK,
@@ -361,32 +378,32 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
),
)
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
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(
for key, value in dict(
sorted(
created_payment_records_dict.items(),
key=lambda x: x[1],
reverse=True
)).items():
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(item_comment=item_comment)
new_decision_book_item.update(is_payment_created=True)
return JSONResponse(
status_code=status.HTTP_200_OK,