migrator completed

This commit is contained in:
2024-11-14 18:11:53 +03:00
parent ac037ae54a
commit 1ae1264ace
23 changed files with 439 additions and 207 deletions

View File

@@ -1,6 +1,7 @@
import typing
from operator import or_
from datetime import datetime, timedelta
from platform import system
from typing import List
from fastapi import HTTPException, status
@@ -174,10 +175,10 @@ class Build(CrudCollection, SelectActionWithEmployee):
Integer, nullable=True, comment="Management Room ID"
)
site_id: Mapped[int] = mapped_column(ForeignKey("build_sites.id"))
site_uu_id: Mapped[str] = mapped_column(String, comment="Site UUID")
address_id: Mapped[int] = mapped_column(ForeignKey("addresses.id"))
address_uu_id: Mapped[str] = mapped_column(String, comment="Address UUID")
site_id: Mapped[int] = mapped_column(ForeignKey("build_sites.id"), nullable=True)
site_uu_id: Mapped[str] = mapped_column(String, comment="Site UUID", nullable=True)
address_id: Mapped[int] = mapped_column(ForeignKey("addresses.id"), nullable=False)
address_uu_id: Mapped[str] = mapped_column(String, comment="Address UUID", nullable=False)
build_types_id: Mapped[int] = mapped_column(
ForeignKey("build_types.id"), nullable=False, comment="Building Type"
)
@@ -243,22 +244,24 @@ class Build(CrudCollection, SelectActionWithEmployee):
).data
data_dict["address_id"] = official_address.id
data_dict["build_no"] = str(official_address.build_number)
data_dict.pop("address_uu_id", None)
if not data_dict["address_id"]:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Address is not found in database. Re-enter address record then try again.",
)
build_type = BuildTypes.find_one(uu_id=str(data.build_types_uu_id))
build_type = BuildTypes.filter_by_one(system=True, uu_id=str(data.build_types_uu_id)).data
data_dict["build_types_id"] = build_type.id
del data_dict["build_types_uu_id"]
build_created = cls.find_or_create(**data_dict)
cls.__many__table__.find_or_create(
created_build_relation = cls.__many__table__.find_or_create(
company_id=token.selected_company.company_id,
employee_id=token.selected_company.employee_id,
member_id=build_created.id,
is_confirmed=True,
)
build_created.save()
build_created.update(is_confirmed=True)
build_created.save()
created_build_relation.update(is_confirmed=True)
created_build_relation.save()
return build_created
@classmethod
@@ -316,7 +319,7 @@ class Build(CrudCollection, SelectActionWithEmployee):
building_types = None
for part in self.parts:
building_types = {}
build_type = BuildTypes.find_one(id=part.build_part_type_id)
build_type = BuildTypes.filter_by_one(system=True, id=part.build_part_type_id).data
if build_type.type_code in building_types:
building_types[build_type.type_code]["list"].append(part.part_no)
else:
@@ -412,13 +415,14 @@ class BuildParts(CrudCollection):
building = build_from_duty.first()
if not building:
raise HTTPException(
status_code=status.HTTP_418_IM_A_TEAPOT,
status_code=status.HTTP_406_NOT_ACCEPTABLE,
detail="This Employee can not reach this building or building uu-id not found in database. "
"Check with your supervisor.",
)
if build_types := BuildTypes.filter_one(
BuildTypes.uu_id == data.build_part_type_uu_id
BuildTypes.uu_id == data.build_part_type_uu_id,
*BuildTypes.valid_record_args(BuildTypes)
).data:
part_direction = ApiEnumDropdown.get_by_uuid(
uuid=str(data.part_direction_uu_id)
@@ -467,7 +471,7 @@ class BuildParts(CrudCollection):
@property
def part_name(self):
if build_type := BuildTypes.find_one(id=self.build_part_type_id):
if build_type := BuildTypes.filter_by_one(system=True, id=self.build_part_type_id).data:
return f"{str(build_type.type_name).upper()} : {str(self.part_no).upper()}"
return f"Undefined:{str(build_type.type_name).upper()}"
@@ -594,6 +598,7 @@ class BuildArea(CrudCollection):
"""
__tablename__ = "build_area"
__exclude__fields__ = []
area_name: Mapped[str] = mapped_column(String, server_default="")
area_code: Mapped[str] = mapped_column(String, server_default="")