save and confirmed added

This commit is contained in:
2024-11-17 16:30:50 +03:00
parent 7e1b26f3c4
commit 295dbe2cd8
48 changed files with 922 additions and 697 deletions

View File

@@ -179,7 +179,9 @@ class Build(CrudCollection, SelectActionWithEmployee):
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)
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"
)
@@ -226,8 +228,8 @@ class Build(CrudCollection, SelectActionWithEmployee):
@property
def management_room(self):
if management_room := BuildParts.find_one(
id=self.management_room_id, build_id=self.id, active=True, is_confirmed=True
if management_room := BuildParts.filter_by_one(
system=True, id=self.management_room_id, build_id=self.id
):
return management_room
return None
@@ -240,7 +242,7 @@ class Build(CrudCollection, SelectActionWithEmployee):
data_dict["address_id"] = None
if data.address_uu_id:
official_address = Addresses.filter_one(
Addresses.uu_id==data.address_uu_id,
Addresses.uu_id == data.address_uu_id,
).data
data_dict["address_id"] = official_address.id
data_dict["build_no"] = str(official_address.build_number)
@@ -249,7 +251,9 @@ class Build(CrudCollection, SelectActionWithEmployee):
status_code=status.HTTP_404_NOT_FOUND,
detail="Address is not found in database. Re-enter address record then try again.",
)
build_type = BuildTypes.filter_by_one(system=True, uu_id=str(data.build_types_uu_id)).data
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
build_created = cls.find_or_create(**data_dict)
created_build_relation = cls.__many__table__.find_or_create(
@@ -304,7 +308,8 @@ class Build(CrudCollection, SelectActionWithEmployee):
@property
def livable_part_count(self):
livable_parts = BuildParts.filter_all(
BuildParts.build_id == self.id, BuildParts.human_livable == True,
BuildParts.build_id == self.id,
BuildParts.human_livable == True,
)
if not livable_parts.data:
raise HTTPException(
@@ -318,7 +323,9 @@ class Build(CrudCollection, SelectActionWithEmployee):
building_types = None
for part in self.parts:
building_types = {}
build_type = BuildTypes.filter_by_one(system=True, id=part.build_part_type_id).data
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:
@@ -363,7 +370,9 @@ class BuildParts(CrudCollection):
part_gross_size: Mapped[int] = mapped_column(
Integer, server_default="0", comment="Part Gross Size"
)
part_net_size: Mapped[int] = mapped_column(Integer, server_default="0", comment="Part Net Size")
part_net_size: Mapped[int] = mapped_column(
Integer, server_default="0", comment="Part Net Size"
)
default_accessory: Mapped[str] = mapped_column(
Text, server_default="0", comment="Default Accessory"
)
@@ -469,7 +478,9 @@ class BuildParts(CrudCollection):
@property
def part_name(self):
if build_type := BuildTypes.filter_by_one(system=True, id=self.build_part_type_id).data:
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()}"
@@ -552,23 +563,21 @@ class BuildLivingSpace(CrudCollection):
from api_events.events.events.events_bind_services import (
ServiceBindOccupantEventMethods,
)
if data.get('expiry_starts'):
data['expiry_starts'] = str(system_arrow.get(data['expiry_starts']))
if data.get('expiry_ends'):
data['expiry_ends'] = str(system_arrow.get(data['expiry_ends']))
if data.get("expiry_starts"):
data["expiry_starts"] = str(system_arrow.get(data["expiry_starts"]))
if data.get("expiry_ends"):
data["expiry_ends"] = str(system_arrow.get(data["expiry_ends"]))
created_living_space = BuildLivingSpace.find_or_create(**data)
occupant_type = OccupantTypes.filter_by_one(
system=True,
uu_id=created_living_space.occupant_type_uu_id
system=True, uu_id=created_living_space.occupant_type_uu_id
).data
related_service = Services.filter_by_one(
related_responsibility=occupant_type.occupant_code,
**Services.valid_record_dict
**Services.valid_record_dict,
).data
created_living_space.save()
created_living_space.is_confirmed = True
created_living_space.save()
created_living_space.save_and_confirm()
if not related_service:
raise HTTPException(
@@ -586,6 +595,7 @@ class BuildLivingSpace(CrudCollection):
cls, customer_id, process_date, add_days: int = 32
):
from api_library.date_time_actions.date_functions import system_arrow
formatted_date = system_arrow.get(str(process_date))
living_spaces = cls.filter_all(
or_(
@@ -642,7 +652,7 @@ class BuildSites(CrudCollection):
__exclude__fields__ = []
__include__fields__ = []
site_name : Mapped[str]= mapped_column(String(24), nullable=False)
site_name: Mapped[str] = mapped_column(String(24), nullable=False)
site_no: Mapped[str] = mapped_column(String(8), nullable=False)
address_id: Mapped[int] = mapped_column(ForeignKey("addresses.id"))
@@ -671,14 +681,22 @@ class BuildCompaniesProviding(CrudCollection):
build_id = mapped_column(
ForeignKey("build.id"), nullable=False, comment="Building ID"
)
build_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Providing UUID")
build_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Providing UUID"
)
company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"))
company_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Providing UUID")
company_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Providing UUID"
)
provide_id: Mapped[int] = mapped_column(
ForeignKey("api_enum_dropdown.id"), nullable=True
)
provide_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Providing UUID")
contract_id: Mapped[int] = mapped_column(Integer, ForeignKey("companies.id"), nullable=True)
provide_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Providing UUID"
)
contract_id: Mapped[int] = mapped_column(
Integer, ForeignKey("companies.id"), nullable=True
)
__table_args__ = (
Index(
@@ -702,14 +720,22 @@ class BuildPersonProviding(CrudCollection):
build_id = mapped_column(
ForeignKey("build.id"), nullable=False, comment="Building ID"
)
build_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Providing UUID")
build_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Providing UUID"
)
people_id: Mapped[int] = mapped_column(ForeignKey("people.id"))
people_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="People UUID")
people_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="People UUID"
)
provide_id: Mapped[int] = mapped_column(
ForeignKey("api_enum_dropdown.id"), nullable=True
)
provide_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Providing UUID")
contract_id: Mapped[int] = mapped_column(Integer, ForeignKey("companies.id"), nullable=True)
provide_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Providing UUID"
)
contract_id: Mapped[int] = mapped_column(
Integer, ForeignKey("companies.id"), nullable=True
)
__table_args__ = (
Index(