decision book create update
This commit is contained in:
parent
1ae1264ace
commit
6ccb13809a
|
|
@ -27,6 +27,12 @@ from api_events.events.authentication import (
|
||||||
AuthenticationForgotPasswordEventMethod,
|
AuthenticationForgotPasswordEventMethod,
|
||||||
AuthenticationDownloadAvatarEventMethod,
|
AuthenticationDownloadAvatarEventMethod,
|
||||||
)
|
)
|
||||||
|
from api_events.events.account.account_records import (
|
||||||
|
AccountRecordsListEventMethod,
|
||||||
|
AccountRecordsCreateEventMethod,
|
||||||
|
AccountRecordsUpdateEventMethod,
|
||||||
|
AccountRecordsPatchEventMethod,
|
||||||
|
)
|
||||||
from api_events.events.identity.users import (
|
from api_events.events.identity.users import (
|
||||||
UserListEventMethod,
|
UserListEventMethod,
|
||||||
UserCreateEventMethod,
|
UserCreateEventMethod,
|
||||||
|
|
@ -163,6 +169,10 @@ __all__ = [
|
||||||
"AuthenticationRefreshTokenEventMethod",
|
"AuthenticationRefreshTokenEventMethod",
|
||||||
"AuthenticationForgotPasswordEventMethod",
|
"AuthenticationForgotPasswordEventMethod",
|
||||||
"AuthenticationDownloadAvatarEventMethod",
|
"AuthenticationDownloadAvatarEventMethod",
|
||||||
|
"AccountRecordsListEventMethod",
|
||||||
|
"AccountRecordsCreateEventMethod",
|
||||||
|
"AccountRecordsUpdateEventMethod",
|
||||||
|
"AccountRecordsPatchEventMethod",
|
||||||
"UserListEventMethod",
|
"UserListEventMethod",
|
||||||
"UserCreateEventMethod",
|
"UserCreateEventMethod",
|
||||||
"UserUpdateEventMethod",
|
"UserUpdateEventMethod",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
from api_library.date_time_actions.date_functions import system_arrow
|
||||||
from api_validations.validations_request import (
|
from api_validations.validations_request import (
|
||||||
InsertAccountRecord,
|
InsertAccountRecord,
|
||||||
UpdateAccountRecord,
|
UpdateAccountRecord,
|
||||||
|
|
@ -13,6 +14,8 @@ from databases import (
|
||||||
AccountRecords,
|
AccountRecords,
|
||||||
BuildIbans,
|
BuildIbans,
|
||||||
)
|
)
|
||||||
|
from databases.sql_models.building.build import Build
|
||||||
|
from databases.sql_models.others.enums import ApiEnumDropdown
|
||||||
|
|
||||||
|
|
||||||
class AccountRecordsListEventMethods(MethodToEvent):
|
class AccountRecordsListEventMethods(MethodToEvent):
|
||||||
|
|
@ -61,12 +64,11 @@ class AccountRecordsCreateEventMethods(MethodToEvent):
|
||||||
data: InsertAccountRecord,
|
data: InsertAccountRecord,
|
||||||
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
||||||
):
|
):
|
||||||
|
data_dict = data.excluded_dump()
|
||||||
if isinstance(token_dict, OccupantTokenObject):
|
if isinstance(token_dict, OccupantTokenObject):
|
||||||
build_iban = BuildIbans.filter_one(
|
build_iban = BuildIbans.filter_one(
|
||||||
BuildIbans.iban == data.iban,
|
BuildIbans.iban == data.iban,
|
||||||
BuildIbans.company_id
|
BuildIbans.build_id == token_dict.selected_occupant.build_id,
|
||||||
== token_dict.selected_occupant.responsible_company_id,
|
|
||||||
).data
|
).data
|
||||||
if not build_iban:
|
if not build_iban:
|
||||||
BuildIbans.raise_http_exception(
|
BuildIbans.raise_http_exception(
|
||||||
|
|
@ -84,23 +86,47 @@ class AccountRecordsCreateEventMethods(MethodToEvent):
|
||||||
result=account_record.get_dict(),
|
result=account_record.get_dict(),
|
||||||
)
|
)
|
||||||
elif isinstance(token_dict, EmployeeTokenObject):
|
elif isinstance(token_dict, EmployeeTokenObject):
|
||||||
build_iban = BuildIbans.filter_one(
|
# Build.pre_query = Build.select_action(
|
||||||
BuildIbans.iban == data.iban,
|
# employee_id=token_dict.selected_employee.employee_id,
|
||||||
BuildIbans.company_id == token_dict.selected_company.company_id,
|
# )
|
||||||
).data
|
# build_ids_list = Build.filter_all(
|
||||||
if not build_iban:
|
# *Build.valid_record_args(Build),
|
||||||
BuildIbans.raise_http_exception(
|
# )
|
||||||
status_code="HTTP_404_NOT_FOUND",
|
# build_iban = BuildIbans.filter_one(
|
||||||
error_case="UNAUTHORIZED",
|
# BuildIbans.iban == data.iban,
|
||||||
message=f"{data.iban} is not found in company related to your organization",
|
# BuildIbans.build_id.in_([build.id for build in build_ids_list.data]),
|
||||||
data={
|
# ).data
|
||||||
"iban": data.iban,
|
# if not build_iban:
|
||||||
},
|
# BuildIbans.raise_http_exception(
|
||||||
)
|
# status_code="HTTP_404_NOT_FOUND",
|
||||||
account_record = AccountRecords.find_or_create(**data.excluded_dump())
|
# 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(
|
return AlchemyJsonResponse(
|
||||||
completed=True,
|
completed=True,
|
||||||
message="Update Build record",
|
message="Create Account record are successful",
|
||||||
result=account_record.get_dict(),
|
result=account_record.get_dict(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ class BuildListEventMethods(MethodToEvent):
|
||||||
Build.filter_attr = list_options
|
Build.filter_attr = list_options
|
||||||
records = Build.filter_all(
|
records = Build.filter_all(
|
||||||
*Build.valid_record_args(Build),
|
*Build.valid_record_args(Build),
|
||||||
).data
|
)
|
||||||
return AlchemyJsonResponse(
|
return AlchemyJsonResponse(
|
||||||
completed=True,
|
completed=True,
|
||||||
message="Building Records are listed",
|
message="Building Records are listed",
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ class BuildingBuildPartsListEventMethods(MethodToEvent):
|
||||||
build_list_ids = [build.id for build in build_list_query.all()]
|
build_list_ids = [build.id for build in build_list_query.all()]
|
||||||
BuildParts.pre_query = BuildParts.filter_all(
|
BuildParts.pre_query = BuildParts.filter_all(
|
||||||
BuildParts.build_id.in_(build_list_ids),
|
BuildParts.build_id.in_(build_list_ids),
|
||||||
*BuildParts.valid_record_args(BuildParts),
|
|
||||||
).query
|
).query
|
||||||
BuildParts.filter_attr = list_options
|
BuildParts.filter_attr = list_options
|
||||||
records = BuildParts.filter_all(
|
records = BuildParts.filter_all(
|
||||||
|
|
@ -64,6 +63,8 @@ class BuildingBuildPartsCreateEventMethods(MethodToEvent):
|
||||||
):
|
):
|
||||||
created_build = BuildParts.create_action(data=data, token=token_dict)
|
created_build = BuildParts.create_action(data=data, token=token_dict)
|
||||||
created_build.save()
|
created_build.save()
|
||||||
|
created_build.update(is_confirmed=True)
|
||||||
|
created_build.save()
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
"completed": True,
|
"completed": True,
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
|
||||||
error_case="UNAUTHORIZED",
|
error_case="UNAUTHORIZED",
|
||||||
message=f"{data.build_parts_uu_id} - Build Part is not found in database. Check build part uu_id",
|
message=f"{data.build_parts_uu_id} - Build Part is not found in database. Check build part uu_id",
|
||||||
data={
|
data={
|
||||||
"life_person_uu_id": data.life_person_uu_id,
|
"build_parts_uu_id": data.build_parts_uu_id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
life_person = People.filter_one(
|
life_person = People.filter_one(
|
||||||
|
|
@ -148,9 +148,9 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
|
||||||
BuildLivingSpace.raise_http_exception(
|
BuildLivingSpace.raise_http_exception(
|
||||||
status_code="HTTP_404_NOT_FOUND",
|
status_code="HTTP_404_NOT_FOUND",
|
||||||
error_case="UNAUTHORIZED",
|
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={
|
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
|
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 = Build.filter_one(
|
||||||
Build.uu_id == data.build_uu_id,
|
Build.uu_id == data.build_uu_id,
|
||||||
Build.active == True,
|
*Build.valid_record_args(Build),
|
||||||
).get(1)
|
).data
|
||||||
if not build:
|
if not build:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
|
|
@ -102,7 +102,7 @@ class DecisionBookCreateEventMethods(MethodToEvent):
|
||||||
company = Companies.filter_one(
|
company = Companies.filter_one(
|
||||||
Companies.uu_id == data.resp_company_uu_id,
|
Companies.uu_id == data.resp_company_uu_id,
|
||||||
*Companies.valid_record_args(Companies),
|
*Companies.valid_record_args(Companies),
|
||||||
).get(1)
|
).data
|
||||||
if not company:
|
if not company:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
|
|
@ -144,11 +144,11 @@ class DecisionBookCreateEventMethods(MethodToEvent):
|
||||||
occupant_build = Build.filter_one(
|
occupant_build = Build.filter_one(
|
||||||
Build.id == token_dict.selected_occupant.build_id,
|
Build.id == token_dict.selected_occupant.build_id,
|
||||||
*Build.valid_record_args(Build),
|
*Build.valid_record_args(Build),
|
||||||
).get(1)
|
).data
|
||||||
occupant_company = Companies.filter_one(
|
occupant_company = Companies.filter_one(
|
||||||
Companies.id == token_dict.selected_occupant.responsible_company_id,
|
Companies.id == token_dict.selected_occupant.responsible_company_id,
|
||||||
*Companies.valid_record_args(Companies),
|
*Companies.valid_record_args(Companies),
|
||||||
).get(1)
|
).data
|
||||||
data_dict["build_id"] = occupant_build.id
|
data_dict["build_id"] = occupant_build.id
|
||||||
data_dict["build_uu_id"] = str(occupant_build.uu_id)
|
data_dict["build_uu_id"] = str(occupant_build.uu_id)
|
||||||
data_dict["resp_company_id"] = occupant_company.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().month),
|
||||||
int(decision_period_date.date().day),
|
int(decision_period_date.date().day),
|
||||||
)
|
)
|
||||||
data_dict["expiry_ends"] = str(
|
data_dict["expiry_ends"] = str(data_dict["expiry_starts"].shift(years=1, days=-1))
|
||||||
data_dict["expiry_starts"].shift(years=1, days=-1)
|
|
||||||
)
|
|
||||||
data_dict["expiry_starts"] = str(data_dict["expiry_starts"])
|
data_dict["expiry_starts"] = str(data_dict["expiry_starts"])
|
||||||
build_decision_book = BuildDecisionBook.find_or_create(**data_dict)
|
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(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_200_OK,
|
status_code=status.HTTP_200_OK,
|
||||||
content=dict(
|
content=dict(
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class PeopleListEventMethods(MethodToEvent):
|
||||||
People.filter_attr = list_options
|
People.filter_attr = list_options
|
||||||
records = People.filter_all(
|
records = People.filter_all(
|
||||||
*People.valid_record_args(People),
|
*People.valid_record_args(People),
|
||||||
).data
|
)
|
||||||
elif isinstance(token_dict, OccupantTokenObject):
|
elif isinstance(token_dict, OccupantTokenObject):
|
||||||
related_users = Users.filter_all(
|
related_users = Users.filter_all(
|
||||||
Users.related_company
|
Users.related_company
|
||||||
|
|
@ -54,7 +54,7 @@ class PeopleListEventMethods(MethodToEvent):
|
||||||
People.filter_attr = list_options
|
People.filter_attr = list_options
|
||||||
records = People.filter_all(
|
records = People.filter_all(
|
||||||
*People.valid_record_args(People),
|
*People.valid_record_args(People),
|
||||||
).data
|
)
|
||||||
return AlchemyJsonResponse(
|
return AlchemyJsonResponse(
|
||||||
completed=True,
|
completed=True,
|
||||||
message="People are listed successfully",
|
message="People are listed successfully",
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,10 @@ class SuperUserEventBlock(AddEventFunctionality):
|
||||||
{"function_code": "76f11a08-5f4a-4e1f-961f-aaef21699acd"},
|
{"function_code": "76f11a08-5f4a-4e1f-961f-aaef21699acd"},
|
||||||
{"function_code": "41ea7f29-006a-4310-b5c4-b2a0e1a504bd"},
|
{"function_code": "41ea7f29-006a-4310-b5c4-b2a0e1a504bd"},
|
||||||
{"function_code": "5344d03c-fc47-43ec-8c44-6c2acd7e5d9f"},
|
{"function_code": "5344d03c-fc47-43ec-8c44-6c2acd7e5d9f"},
|
||||||
|
{"function_code": "31f4f32f-0cd4-4995-8a6a-f9f56335848a"},
|
||||||
|
{"function_code": "7192c2aa-5352-4e36-98b3-dafb7d036a3d"},
|
||||||
|
{"function_code": "ec98ef2c-bcd0-432d-a8f4-1822a56c33b2"},
|
||||||
|
{"function_code": "34c38937-42a2-45f1-b2ef-a23978650aee"},
|
||||||
]
|
]
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs):
|
def __new__(cls, *args, **kwargs):
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,20 @@ class AlchemyJsonResponse:
|
||||||
cls.result = result
|
cls.result = result
|
||||||
cls.completed = completed
|
cls.completed = completed
|
||||||
|
|
||||||
first_item = cls.result.get(1)
|
if isinstance(cls.result, dict) or isinstance(cls.result, list):
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=cls.status_code,
|
||||||
|
content=dict(
|
||||||
|
total_count=len(cls.result),
|
||||||
|
count=len(cls.result),
|
||||||
|
pagination=None,
|
||||||
|
completed=cls.completed,
|
||||||
|
message=cls.message,
|
||||||
|
data=cls.result,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
first_item = getattr(cls.result, 'data', None)
|
||||||
if not first_item:
|
if not first_item:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=cls.status_code,
|
status_code=cls.status_code,
|
||||||
|
|
@ -39,6 +52,7 @@ class AlchemyJsonResponse:
|
||||||
data=[],
|
data=[],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
if cls.result.first:
|
if cls.result.first:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=cls.status_code,
|
status_code=cls.status_code,
|
||||||
|
|
@ -52,7 +66,7 @@ class AlchemyJsonResponse:
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
if not first_item.filter_attr:
|
if not cls.result.get(1).filter_attr and isinstance(cls.result.data, list):
|
||||||
counts = cls.result.count
|
counts = cls.result.count
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=cls.status_code,
|
status_code=cls.status_code,
|
||||||
|
|
@ -66,9 +80,10 @@ class AlchemyJsonResponse:
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
filter_model = first_item.filter_attr
|
filter_model = cls.result.get(1).filter_attr
|
||||||
total_count = cls.result.query.limit(None).offset(None).count()
|
total_count = cls.result.get(1).query.limit(None).offset(None).count()
|
||||||
total_page_number = round(total_count / int(first_item.filter_attr.size), 0)
|
|
||||||
|
total_page_number = round(total_count / int(filter_model.size), 0)
|
||||||
|
|
||||||
pagination_dict = {
|
pagination_dict = {
|
||||||
"size/total_count": [cls.result.count, total_count],
|
"size/total_count": [cls.result.count, total_count],
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ class InsertAccountRecord(BaseModelRegular):
|
||||||
accounting_receipt_number: Optional[int] = None
|
accounting_receipt_number: Optional[int] = None
|
||||||
approved_record: Optional[bool] = None
|
approved_record: Optional[bool] = None
|
||||||
import_file_name: Optional[str] = None
|
import_file_name: Optional[str] = None
|
||||||
receive_debit_uu_id: Optional[str] = None
|
# receive_debit_uu_id: Optional[str] = None
|
||||||
budget_type_uu_id: Optional[str] = None
|
budget_type_uu_id: Optional[str] = None
|
||||||
company_uu_id: Optional[str] = None
|
company_uu_id: Optional[str] = None
|
||||||
send_company_uu_id: Optional[str] = None
|
send_company_uu_id: Optional[str] = None
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ class InsertBuildParts(PydanticBaseModel):
|
||||||
default_accessory: Optional[str] = None
|
default_accessory: Optional[str] = None
|
||||||
human_livable: Optional[bool] = False
|
human_livable: Optional[bool] = False
|
||||||
part_direction_uu_id: Optional[str] = None
|
part_direction_uu_id: Optional[str] = None
|
||||||
|
ref_id: Optional[str] = None
|
||||||
|
|
||||||
# current_owner_person_uu_id: Optional[str] = None
|
# current_owner_person_uu_id: Optional[str] = None
|
||||||
# current_tenant_person_uu_id: Optional[str] = None
|
# current_tenant_person_uu_id: Optional[str] = None
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ class InsertPerson(BaseModelRegular):
|
||||||
birth_place: Optional[str] = None
|
birth_place: Optional[str] = None
|
||||||
birth_date: Optional[str] = None
|
birth_date: Optional[str] = None
|
||||||
tax_no: Optional[str] = None
|
tax_no: Optional[str] = None
|
||||||
|
ref_id: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class ResponsePersonSalesMange(PydanticBaseModel):
|
class ResponsePersonSalesMange(PydanticBaseModel):
|
||||||
|
|
|
||||||
|
|
@ -430,48 +430,44 @@ class AccountRecords(CrudCollection):
|
||||||
approving_accounting_record: Mapped[bool] = mapped_column(
|
approving_accounting_record: Mapped[bool] = mapped_column(
|
||||||
Boolean, server_default="0"
|
Boolean, server_default="0"
|
||||||
)
|
)
|
||||||
accounting_receipt_date = mapped_column(
|
accounting_receipt_date: Mapped[TIMESTAMP] = mapped_column(
|
||||||
TIMESTAMP, server_default="1900-01-01 00:00:00"
|
TIMESTAMP, server_default="1900-01-01 00:00:00"
|
||||||
)
|
)
|
||||||
accounting_receipt_number = mapped_column(Integer, server_default="0")
|
accounting_receipt_number: Mapped[int] = mapped_column(Integer, server_default="0")
|
||||||
status_id = mapped_column(SmallInteger, server_default="0")
|
status_id: Mapped[int] = mapped_column(SmallInteger, server_default="0")
|
||||||
|
|
||||||
approved_record: Mapped[bool] = mapped_column(Boolean, server_default="0")
|
approved_record: Mapped[bool] = mapped_column(Boolean, server_default="0")
|
||||||
import_file_name = mapped_column(String, nullable=True, comment="XLS Key")
|
import_file_name: Mapped[str] = mapped_column(String, nullable=True, comment="XLS Key")
|
||||||
|
|
||||||
receive_debit: Mapped[int] = mapped_column(ForeignKey("api_enum_dropdown.id"))
|
receive_debit: Mapped[int] = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True)
|
||||||
receive_debit_uu_id = mapped_column(String, nullable=True, comment="Debit UU ID")
|
receive_debit_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Debit UU ID")
|
||||||
budget_type: Mapped[int] = mapped_column(
|
budget_type: Mapped[int] = mapped_column(
|
||||||
ForeignKey("api_enum_dropdown.id"), nullable=True
|
ForeignKey("api_enum_dropdown.id"), nullable=True
|
||||||
)
|
)
|
||||||
budget_type_uu_id = mapped_column(
|
budget_type_uu_id: Mapped[str] = mapped_column(
|
||||||
String, nullable=True, comment="Budget Type UU ID"
|
String, nullable=True, comment="Budget Type UU ID"
|
||||||
)
|
)
|
||||||
|
|
||||||
company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"))
|
company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"), nullable=True)
|
||||||
company_uu_id = mapped_column(String, nullable=True, comment="Company UU ID")
|
company_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Company UU ID")
|
||||||
send_company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"))
|
send_company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"), nullable=True)
|
||||||
send_company_uu_id = mapped_column(
|
send_company_uu_id = mapped_column(String, nullable=True, comment="Send Company UU ID" )
|
||||||
String, nullable=True, comment="Send Company UU ID"
|
|
||||||
)
|
|
||||||
|
|
||||||
customer_id: Mapped[int] = mapped_column(ForeignKey("people.id"))
|
customer_id: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=True)
|
||||||
customer_uu_id = mapped_column(String, nullable=True, comment="Customer UU ID")
|
customer_uu_id = mapped_column(String, nullable=True, comment="Customer UU ID")
|
||||||
send_person_id: Mapped[int] = mapped_column(ForeignKey("people.id"))
|
send_person_id: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=True)
|
||||||
send_person_uu_id = mapped_column(
|
send_person_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Send Person UU ID")
|
||||||
String, nullable=True, comment="Send Person UU ID"
|
approving_accounting_person: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=True)
|
||||||
)
|
approving_accounting_person_uu_id: Mapped[str] = mapped_column(
|
||||||
approving_accounting_person: Mapped[int] = mapped_column(ForeignKey("people.id"))
|
|
||||||
approving_accounting_person_uu_id = mapped_column(
|
|
||||||
String, nullable=True, comment="Approving Accounting Person UU ID"
|
String, nullable=True, comment="Approving Accounting Person UU ID"
|
||||||
)
|
)
|
||||||
# build_id: Mapped[int] = mapped_column(ForeignKey("build.id"), nullable=True)
|
# build_id: Mapped[int] = mapped_column(ForeignKey("build.id"), nullable=True)
|
||||||
build_parts_id: Mapped[int] = mapped_column(ForeignKey("build_parts.id"))
|
build_parts_id: Mapped[int] = mapped_column(ForeignKey("build_parts.id"), nullable=True)
|
||||||
build_parts_uu_id: Mapped[str] = mapped_column(
|
build_parts_uu_id: Mapped[str] = mapped_column(
|
||||||
String, nullable=True, comment="Build Parts UU ID"
|
String, nullable=True, comment="Build Parts UU ID"
|
||||||
)
|
)
|
||||||
build_decision_book_id: Mapped[int] = mapped_column(
|
build_decision_book_id: Mapped[int] = mapped_column(
|
||||||
ForeignKey("build_decision_book.id")
|
ForeignKey("build_decision_book.id"), nullable=True
|
||||||
)
|
)
|
||||||
build_decision_book_uu_id: Mapped[str] = mapped_column(
|
build_decision_book_uu_id: Mapped[str] = mapped_column(
|
||||||
String, nullable=True, comment="Build Decision Book UU ID"
|
String, nullable=True, comment="Build Decision Book UU ID"
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ class FilterAttributes:
|
||||||
__session__ = Base.session # The session to use in the model.
|
__session__ = Base.session # The session to use in the model.
|
||||||
|
|
||||||
pre_query = None # The query to use before the filtering such as: query = cls.query.filter_by(active=True)
|
pre_query = None # The query to use before the filtering such as: query = cls.query.filter_by(active=True)
|
||||||
|
total_count = None # The query to use before the filtering such as: query = cls.query.filter_by(active=True)
|
||||||
filter_attr = None # The filter attributes to use in the model.
|
filter_attr = None # The filter attributes to use in the model.
|
||||||
FilterModel = ListOptions
|
FilterModel = ListOptions
|
||||||
|
|
||||||
|
|
@ -130,6 +131,7 @@ class FilterAttributes:
|
||||||
)
|
)
|
||||||
args = cls.get_not_expired_query_arg(args)
|
args = cls.get_not_expired_query_arg(args)
|
||||||
query = cls._query().filter(*args).with_entities(*select_args)
|
query = cls._query().filter(*args).with_entities(*select_args)
|
||||||
|
cls.total_count = query.count()
|
||||||
if order_by is not None:
|
if order_by is not None:
|
||||||
query = query.order_by(order_by)
|
query = query.order_by(order_by)
|
||||||
if limit:
|
if limit:
|
||||||
|
|
@ -145,9 +147,11 @@ class FilterAttributes:
|
||||||
kwargs["is_confirmed"] = True
|
kwargs["is_confirmed"] = True
|
||||||
kwargs.pop("system", None)
|
kwargs.pop("system", None)
|
||||||
query = cls._query().filter_by(**kwargs)
|
query = cls._query().filter_by(**kwargs)
|
||||||
|
cls.total_count = query.count()
|
||||||
if cls.filter_attr:
|
if cls.filter_attr:
|
||||||
filter_list = cls.get_filter_attributes()
|
filter_list = cls.get_filter_attributes()
|
||||||
data_query = cls.add_query_to_filter(query, filter_list)
|
data_query = cls.add_query_to_filter(query, filter_list)
|
||||||
|
cls.filter_attr = None
|
||||||
return AlchemyResponse(query=data_query, first=False)
|
return AlchemyResponse(query=data_query, first=False)
|
||||||
return AlchemyResponse(query=query, first=False)
|
return AlchemyResponse(query=query, first=False)
|
||||||
|
|
||||||
|
|
@ -160,6 +164,7 @@ class FilterAttributes:
|
||||||
kwargs["is_confirmed"] = True
|
kwargs["is_confirmed"] = True
|
||||||
kwargs.pop("system", None)
|
kwargs.pop("system", None)
|
||||||
query = cls._query().filter_by(**kwargs)
|
query = cls._query().filter_by(**kwargs)
|
||||||
|
cls.total_count = 1
|
||||||
return AlchemyResponse(query=query, first=True)
|
return AlchemyResponse(query=query, first=True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -174,9 +179,11 @@ class FilterAttributes:
|
||||||
args = cls.get_not_expired_query_arg(args)
|
args = cls.get_not_expired_query_arg(args)
|
||||||
|
|
||||||
query = cls._query().filter(*args)
|
query = cls._query().filter(*args)
|
||||||
|
cls.total_count = query.count()
|
||||||
if cls.filter_attr:
|
if cls.filter_attr:
|
||||||
filter_list = cls.get_filter_attributes()
|
filter_list = cls.get_filter_attributes()
|
||||||
data_query = cls.add_query_to_filter(query, filter_list)
|
data_query = cls.add_query_to_filter(query, filter_list)
|
||||||
|
cls.filter_attr = None
|
||||||
return AlchemyResponse(query=data_query, first=False)
|
return AlchemyResponse(query=data_query, first=False)
|
||||||
return AlchemyResponse(query=query, first=False)
|
return AlchemyResponse(query=query, first=False)
|
||||||
|
|
||||||
|
|
@ -191,6 +198,7 @@ class FilterAttributes:
|
||||||
)
|
)
|
||||||
args = cls.get_not_expired_query_arg(args)
|
args = cls.get_not_expired_query_arg(args)
|
||||||
query = cls._query().filter(*args)
|
query = cls._query().filter(*args)
|
||||||
|
cls.total_count = 1
|
||||||
return AlchemyResponse(query=query, first=True)
|
return AlchemyResponse(query=query, first=True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
from service_app_test.api_configs import BothAPIS
|
||||||
|
from service_app_test.test_application.migrate_old_data.reader_and_alchemy_bulk_actions import (
|
||||||
|
read_json_file,
|
||||||
|
)
|
||||||
|
from api_validations.validations_request import (
|
||||||
|
InsertAccountRecord,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_account_records_from_json():
|
||||||
|
read_files_json, with_pydantic = read_json_file(json_file="account_records"), []
|
||||||
|
read_files = read_files_json.get("account_records")
|
||||||
|
for row in read_files:
|
||||||
|
if not row['bank_reference_code']:
|
||||||
|
row['bank_reference_code'] = "NOT FOUND"
|
||||||
|
pydantic_row = InsertAccountRecord(**row)
|
||||||
|
with_pydantic.append(pydantic_row.model_dump())
|
||||||
|
if not with_pydantic:
|
||||||
|
raise Exception("No data found")
|
||||||
|
return with_pydantic
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_account_records(requester: BothAPIS):
|
||||||
|
account_records = get_account_records_from_json()
|
||||||
|
for account_record in account_records:
|
||||||
|
response = requester.local_api.post(
|
||||||
|
endpoint="/account/records/create", data=account_record
|
||||||
|
)
|
||||||
|
print('response.text', response.text)
|
||||||
|
print('response.status_code', response.json())
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from service_app_test.api_configs import BothAPIS
|
from service_app_test.api_configs import BothAPIS
|
||||||
from service_app_test.test_application.evyos.address_building import post_code_dict
|
from service_app_test.test_application.evyos.address_building import post_code_dict
|
||||||
|
from service_app_test.test_application.migrate_old_data.get_occupants_codes import get_occupants_types
|
||||||
from service_app_test.test_application.migrate_old_data.reader_and_alchemy_bulk_actions import (
|
from service_app_test.test_application.migrate_old_data.reader_and_alchemy_bulk_actions import (
|
||||||
read_json_file,
|
read_json_file,
|
||||||
)
|
)
|
||||||
|
|
@ -58,10 +59,15 @@ def get_build_part_from_json(build_part_type_uu_id: str, part_direction_uu_id: s
|
||||||
for row in read_files:
|
for row in read_files:
|
||||||
row["build_part_type_uu_id"] = build_part_type_uu_id
|
row["build_part_type_uu_id"] = build_part_type_uu_id
|
||||||
row["part_direction_uu_id"] = part_direction_uu_id
|
row["part_direction_uu_id"] = part_direction_uu_id
|
||||||
|
row["ref_id"] = row.get("uu_id")
|
||||||
pydantic_row = InsertBuildParts(**row)
|
pydantic_row = InsertBuildParts(**row)
|
||||||
with_pydantic.append(pydantic_row.model_dump())
|
print(f"get buildpart row {pydantic_row.dump()}")
|
||||||
|
model_dump = pydantic_row.dump()
|
||||||
|
with_pydantic.append(model_dump)
|
||||||
|
|
||||||
if not with_pydantic:
|
if not with_pydantic:
|
||||||
raise Exception("No data found")
|
raise Exception("No data found")
|
||||||
|
|
||||||
return with_pydantic
|
return with_pydantic
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -203,15 +209,40 @@ def migrate_build_iban(requester: BothAPIS, build_uu_id: str):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def migrate_build_living_space(requester: BothAPIS, build_uu_id: str):
|
def migrate_build_living_space(requester: BothAPIS):
|
||||||
# build_uu_id = grab_new_build_uu_id(requester=requester, build_uu_id=build_uu_id)
|
response_datas = get_build_living_space_from_json()
|
||||||
response_datas = get_build_iban_from_json()
|
|
||||||
for response_data in response_datas:
|
for response_data in response_datas:
|
||||||
response_data["build_uu_id"] = build_uu_id
|
response = requester.local_api.post(
|
||||||
|
endpoint="/people/list",
|
||||||
|
data={"page": 1, "size": 1, "query": {"ref_id": response_data.get("person_uu_id")}},
|
||||||
|
)
|
||||||
|
print("/people/list response", response.text)
|
||||||
|
|
||||||
|
response_data["person_uu_id"] = response.json()["data"][0]["uu_id"]
|
||||||
|
|
||||||
|
response = requester.local_api.post(
|
||||||
|
endpoint="/building/parts/list",
|
||||||
|
data={"page": 1, "size": 1, "query": {"ref_id": response_data.get("build_parts_uu_id")}},
|
||||||
|
)
|
||||||
|
print("/building/parts/list response", response.text)
|
||||||
|
response_data["build_parts_uu_id"] = response.json()["data"][0]["uu_id"]
|
||||||
|
|
||||||
|
flat_owner = "b9392bef-32cb-4c7d-b99f-5f613c2e2120"
|
||||||
|
flat_tenants = "a40aea36-0dce-48cc-9334-2e776ba22a49"
|
||||||
|
if response_data.get('occupant_type_uu_id') == flat_owner:
|
||||||
|
response = get_occupants_types(occupant_code="FL-OWN", requester=requester.local_api)
|
||||||
|
response_data["occupant_type_uu_id"] = response["data"]["uu_id"]
|
||||||
|
elif response_data.get('occupant_type_uu_id') == flat_tenants:
|
||||||
|
response = get_occupants_types(occupant_code="FL-TEN", requester=requester.local_api)
|
||||||
|
response_data["occupant_type_uu_id"] = response["data"]["uu_id"]
|
||||||
|
else:
|
||||||
|
response = get_occupants_types(occupant_code="FL-RES", requester=requester.local_api)
|
||||||
|
response_data["occupant_type_uu_id"] = response["data"]["uu_id"]
|
||||||
|
|
||||||
response = requester.local_api.post(
|
response = requester.local_api.post(
|
||||||
**requester_dict_build_living_space(data=response_data)
|
**requester_dict_build_living_space(data=response_data)
|
||||||
)
|
)
|
||||||
print("response", response.text)
|
print("migrate_build_living_space", response.text)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -251,5 +282,5 @@ def migrate_build(requester: BothAPIS):
|
||||||
build_part_type_uu_id=building_type_flat,
|
build_part_type_uu_id=building_type_flat,
|
||||||
part_direction_uu_id=api_enum_dropdown_nn_uuid
|
part_direction_uu_id=api_enum_dropdown_nn_uuid
|
||||||
)
|
)
|
||||||
migrate_build_iban(requester=requester, build_uu_id=build_uu_id)
|
# migrate_build_iban(requester=requester, build_uu_id=build_uu_id)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -3,11 +3,13 @@ from service_app_test.api_configs import WagAPI, LocalAPI, BothAPIS
|
||||||
|
|
||||||
from service_app_test.test_application.migrate_old_data.people import migrate_people
|
from service_app_test.test_application.migrate_old_data.people import migrate_people
|
||||||
from service_app_test.test_application.migrate_old_data.building import (
|
from service_app_test.test_application.migrate_old_data.building import (
|
||||||
migrate_build,
|
migrate_build, migrate_build_living_space,
|
||||||
)
|
)
|
||||||
from service_app_test.test_application.migrate_old_data.company import migrate_company
|
from service_app_test.test_application.migrate_old_data.company import migrate_company
|
||||||
|
from service_app_test.test_application.migrate_old_data.accounts import migrate_account_records
|
||||||
|
|
||||||
password_token = "b-4liqvEJIX9wtmMScnJhDOkPTIvyra1I_1HQCgTKG3Mp6Oaj-Vh8dVqqpZFC-fGlQ-5bnuDpzrju4Jg6qoi48EB5brdNT4YQCLdQqMlO8uUrL8iuJmRPk4L9AOQl82NFXD0U4pbZ9fhZkp4vHl487S9HcO1Dz5qUYR1VOs5mt2p0d96c5qrWB4QcDkkbz2F"
|
|
||||||
|
password_token = "D0UjFwQjReEjhQuXzytYXj_tPkkFPbRJsj_0Pp9ha2dlvaEj5jC9b76J7UPfKb-s_UqJQAXvRgP3jaKyfTvc_POtMQFALiLzlPUp4Sg-Qjiz9wEECJNc8fWqbfNPtLOFzV5XktV72Whnb4AJYr4pQ9AnuGm4txQnjB_NTPnuZYjyLVnqj9mrLkDKzuXLPSVd"
|
||||||
login_data = {
|
login_data = {
|
||||||
"domain": "evyos.com.tr",
|
"domain": "evyos.com.tr",
|
||||||
"access_key": "karatay.berkay.sup@evyos.com.tr",
|
"access_key": "karatay.berkay.sup@evyos.com.tr",
|
||||||
|
|
@ -42,3 +44,6 @@ both_apis.local_api = local_api
|
||||||
migrate_company(requester=both_apis)
|
migrate_company(requester=both_apis)
|
||||||
migrate_people(requester=both_apis)
|
migrate_people(requester=both_apis)
|
||||||
migrate_build(requester=both_apis)
|
migrate_build(requester=both_apis)
|
||||||
|
migrate_build_living_space(requester=both_apis)
|
||||||
|
|
||||||
|
# migrate_account_records(requester=both_apis)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue