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

@@ -16,18 +16,19 @@ from sqlalchemy import (
TIMESTAMP,
Text,
Numeric,
Identity,
)
from databases.sql_models.core_mixin import CrudCollection
from databases import ApiEnumDropdown
from application.shared_classes import SelectActionWithEmployee, Explanation
from validations import (
from databases.extensions.selector_classes import SelectActionWithEmployee, Explanation
from api_validations.validations_request import (
InsertBuildParts,
InsertBuild,
UpdateBuild,
)
from valids.auth.token_validations import EmployeeTokenObject, OccupantTokenObject
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
class AbstractBuild:
@@ -119,16 +120,16 @@ class BuildTypes(CrudCollection):
__exclude__fields__ = []
__include__fields__ = []
function_code = mapped_column(
function_code: Mapped[str] = mapped_column(
String(12), server_default="", nullable=False, comment="Function Code"
)
type_code = mapped_column(
type_code: Mapped[str] = mapped_column(
String(12), server_default="", nullable=False, comment="Structure Type Code"
)
lang = mapped_column(
lang: Mapped[str] = mapped_column(
String(4), server_default="TR", nullable=False, comment="Language"
)
type_name = mapped_column(
type_name: Mapped[str] = mapped_column(
String(48), server_default="", nullable=False, comment="Type Name"
)
@@ -148,11 +149,11 @@ class Part2Employee(CrudCollection):
__exclude__fields__ = []
__include__fields__ = []
build_id = mapped_column(Integer, comment="Building ID")
part_id = mapped_column(
build_id: Mapped[int] = mapped_column(Integer, comment="Building ID")
part_id: Mapped[Identity] = mapped_column(
ForeignKey("build_parts.id"), nullable=False, comment="Part ID"
)
employee_id = mapped_column(
employee_id: Mapped[Identity] = mapped_column(
ForeignKey("employees.id"), nullable=False, comment="Employee ID"
)
@@ -172,16 +173,20 @@ class RelationshipEmployee2Build(CrudCollection):
__tablename__ = "relationship_employee2build"
__exclude__fields__ = []
company_id = mapped_column(ForeignKey("companies.id"), nullable=False) # 1, 2, 3
employee_id = mapped_column(
company_id: Mapped[Identity] = mapped_column(
ForeignKey("companies.id"), nullable=False
) # 1, 2, 3
employee_id: Mapped[Identity] = mapped_column(
ForeignKey("employees.id"), nullable=False
) # employee -> (n)person Evyos LTD
member_id = mapped_column(ForeignKey("build.id"), nullable=False) # 2, 3, 4
member_id: Mapped[Identity] = mapped_column(
ForeignKey("build.id"), nullable=False
) # 2, 3, 4
relationship_type = mapped_column(
relationship_type: Mapped[str] = mapped_column(
String, nullable=True, server_default="Employee"
) # Commercial
show_only = mapped_column(Boolean, server_default="False")
show_only: Mapped[bool] = mapped_column(Boolean, server_default="False")
__table_args__ = (
Index(
@@ -208,44 +213,56 @@ class Build(CrudCollection, SelectActionWithEmployee):
__many__table__ = RelationshipEmployee2Build
__explain__ = AbstractBuild()
gov_address_code = mapped_column(String, server_default="", unique=True)
build_name = mapped_column(String, nullable=False, comment="Building Name")
build_no = mapped_column(String(8), nullable=False, comment="Building Number")
gov_address_code: Mapped[str] = mapped_column(
String, server_default="", unique=True
)
build_name: Mapped[str] = mapped_column(
String, nullable=False, comment="Building Name"
)
build_no: Mapped[str] = mapped_column(
String(8), nullable=False, comment="Building Number"
)
max_floor = mapped_column(
max_floor: Mapped[int] = mapped_column(
SmallInteger, server_default="1", nullable=False, comment="Max Floor"
)
underground_floor = mapped_column(
underground_floor: Mapped[int] = mapped_column(
SmallInteger, server_default="0", nullable=False, comment="Underground Floor"
)
build_date = mapped_column(TIMESTAMP, server_default="1900-01-01")
decision_period_date = mapped_column(
build_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, server_default="1900-01-01"
)
decision_period_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP,
server_default="1900-01-01",
comment="Building annual ordinary meeting period",
)
tax_no = mapped_column(String(24), server_default="")
lift_count = mapped_column(SmallInteger, server_default="0")
heating_system = mapped_column(Boolean, server_default="True")
cooling_system = mapped_column(Boolean, server_default="False")
hot_water_system = mapped_column(Boolean, server_default="False")
block_service_man_count = mapped_column(SmallInteger, server_default="0")
security_service_man_count = mapped_column(SmallInteger, server_default="0")
garage_count = mapped_column(
tax_no: Mapped[str] = mapped_column(String(24), server_default="")
lift_count: Mapped[int] = mapped_column(SmallInteger, server_default="0")
heating_system: Mapped[bool] = mapped_column(Boolean, server_default="True")
cooling_system: Mapped[bool] = mapped_column(Boolean, server_default="False")
hot_water_system: Mapped[bool] = mapped_column(Boolean, server_default="False")
block_service_man_count: Mapped[int] = mapped_column(
SmallInteger, server_default="0"
)
security_service_man_count: Mapped[int] = mapped_column(
SmallInteger, server_default="0"
)
garage_count: Mapped[int] = mapped_column(
SmallInteger, server_default="0", comment="Garage Count"
)
management_room_id = mapped_column(
management_room_id: Mapped[int] = mapped_column(
Integer, nullable=True, comment="Management Room ID"
)
site_id = mapped_column(ForeignKey("build_sites.id"))
site_uu_id = mapped_column(String, comment="Site UUID")
address_id = mapped_column(ForeignKey("addresses.id"))
address_uu_id = mapped_column(String, comment="Address UUID")
site_id: Mapped[Identity] = mapped_column(ForeignKey("build_sites.id"))
site_uu_id: Mapped[str] = mapped_column(String, comment="Site UUID")
address_id: Mapped[Identity] = mapped_column(ForeignKey("addresses.id"))
address_uu_id: Mapped[str] = mapped_column(String, comment="Address UUID")
build_types_id = mapped_column(
ForeignKey("build_types.id"), nullable=False, comment="Building Type"
)
build_types_uu_id = mapped_column(String, comment="Building Type UUID")
build_types_uu_id: Mapped[str] = mapped_column(String, comment="Building Type UUID")
parts: Mapped[List["BuildParts"]] = relationship(
"BuildParts", back_populates="buildings", foreign_keys="BuildParts.build_id"
@@ -296,7 +313,7 @@ class Build(CrudCollection, SelectActionWithEmployee):
@classmethod
def create_action(cls, data: InsertBuild, token):
from database_sql_models import Addresses
from databases import Addresses
data_dict = data.excluded_dump()
data_dict["address_id"] = None
@@ -325,7 +342,7 @@ class Build(CrudCollection, SelectActionWithEmployee):
@classmethod
def update_action(cls, data: UpdateBuild, build_uu_id: str, token):
from database_sql_models import Addresses
from databases import Addresses
data_dict = data.excluded_dump()
if data.official_address_uu_id:
@@ -405,7 +422,7 @@ class BuildParts(CrudCollection):
address_gov_code = mapped_column(
String, nullable=False, comment="Goverment Door Code"
)
# part_name = mapped_column(String(24), server_default="", nullable=False, comment="Part Name")
# part_name: Mapped[str] = mapped_column(String(24), server_default="", nullable=False, comment="Part Name")
part_no = mapped_column(
SmallInteger, server_default="0", nullable=False, comment="Part Number"
)
@@ -422,7 +439,9 @@ class BuildParts(CrudCollection):
default_accessory = mapped_column(
Text, server_default="0", comment="Default Accessory"
)
human_livable = mapped_column(Boolean, server_default="1", comment="Human Livable")
human_livable: Mapped[bool] = mapped_column(
Boolean, server_default="1", comment="Human Livable"
)
due_part_key = mapped_column(
String, server_default="", nullable=False, comment="Constant Payment Group"
)
@@ -430,8 +449,12 @@ class BuildParts(CrudCollection):
build_id = mapped_column(
ForeignKey("build.id"), nullable=False, comment="Building ID"
)
build_uu_id = mapped_column(String, nullable=False, comment="Building UUID")
part_direction_id = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True)
build_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Building UUID"
)
part_direction_id: Mapped[Identity] = mapped_column(
ForeignKey("api_enum_dropdown.id"), nullable=True
)
part_direction_uu_id = mapped_column(
String, nullable=True, comment="Part Direction UUID"
)
@@ -541,11 +564,15 @@ class BuildLivingSpace(CrudCollection):
comment="Fixed percent is deducted from debit.",
)
agreement_no = mapped_column(String, server_default="", comment="Agreement No")
marketing_process = mapped_column(Boolean, server_default="False")
agreement_no: Mapped[str] = mapped_column(
String, server_default="", comment="Agreement No"
)
marketing_process: Mapped[bool] = mapped_column(Boolean, server_default="False")
marketing_layer = mapped_column(SmallInteger, server_default="0")
discounted_percentage = mapped_column(Numeric(6, 2), server_default="0.00") # %22
discounted_percentage: Mapped[float] = mapped_column(
Numeric(6, 2), server_default="0.00"
) # %22
discounted_price = mapped_column(
Numeric(20, 2), server_default="0.00"
) # Normal: 78.00 TL
@@ -559,7 +586,9 @@ class BuildLivingSpace(CrudCollection):
index=True,
comment="Build Part ID",
)
build_parts_uu_id = mapped_column(String, nullable=False, comment="Build Part UUID")
build_parts_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Build Part UUID"
)
person_id = mapped_column(
ForeignKey("people.id"),
nullable=False,
@@ -588,7 +617,9 @@ class BuildLivingSpace(CrudCollection):
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
):
from databases import Services, OccupantTypes
from api_events.events.events.events_bind_services import ServiceBindOccupantEventMethods
from api_events.events.events.events_bind_services import (
ServiceBindOccupantEventMethods,
)
created_living_space = BuildLivingSpace.find_or_create(**data)
occupant_type = OccupantTypes.find_one(
@@ -632,16 +663,16 @@ class BuildArea(CrudCollection):
__tablename__ = "build_area"
area_name = mapped_column(String, server_default="")
area_code = mapped_column(String, server_default="")
area_type = mapped_column(String, server_default="GREEN")
area_direction = mapped_column(String(2), server_default="NN")
area_gross_size = mapped_column(Numeric(20, 6), server_default="0")
area_net_size = mapped_column(Numeric(20, 6), server_default="0")
area_name: Mapped[str] = mapped_column(String, server_default="")
area_code: Mapped[str] = mapped_column(String, server_default="")
area_type: Mapped[str] = mapped_column(String, server_default="GREEN")
area_direction: Mapped[str] = mapped_column(String(2), server_default="NN")
area_gross_size: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
area_net_size: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
width = mapped_column(Integer, server_default="0")
size = mapped_column(Integer, server_default="0")
build_id = mapped_column(ForeignKey("build.id"))
build_id: Mapped[Identity] = mapped_column(ForeignKey("build.id"))
build_uu_id = mapped_column(String, comment="Building UUID")
part_type_id = mapped_column(
ForeignKey("build_types.id"), nullable=True, comment="Building Part Type"
@@ -671,7 +702,7 @@ class BuildSites(CrudCollection):
site_name = mapped_column(String(24), nullable=False)
site_no = mapped_column(String(8), nullable=False)
address_id = mapped_column(ForeignKey("addresses.id"))
address_id: Mapped[Identity] = mapped_column(ForeignKey("addresses.id"))
address_uu_id = mapped_column(String, comment="Address UUID")
# addresses: Mapped["Address"] = relationship(
@@ -688,47 +719,63 @@ class BuildSites(CrudCollection):
class BuildCompaniesProviding(CrudCollection):
"""
"""
""" """
__tablename__ = "build_companies_providing"
__exclude__fields__ = []
__include__fields__ = []
build_id = mapped_column(ForeignKey("build.id"), nullable=False, comment="Building ID")
build_id = mapped_column(
ForeignKey("build.id"), nullable=False, comment="Building ID"
)
build_uu_id = mapped_column(String, nullable=True, comment="Providing UUID")
company_id = mapped_column(ForeignKey("companies.id"))
company_id: Mapped[Identity] = mapped_column(ForeignKey("companies.id"))
company_uu_id = mapped_column(String, nullable=True, comment="Providing UUID")
provide_id = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True)
provide_id: Mapped[Identity] = mapped_column(
ForeignKey("api_enum_dropdown.id"), nullable=True
)
provide_uu_id = mapped_column(String, nullable=True, comment="Providing UUID")
contract_id = mapped_column(Integer, ForeignKey('companies.id'), nullable=True)
contract_id = mapped_column(Integer, ForeignKey("companies.id"), nullable=True)
__table_args__ = (
Index("_build_companies_providing_ndx_00", build_id, company_id, provide_id , unique=True),
Index(
"_build_companies_providing_ndx_00",
build_id,
company_id,
provide_id,
unique=True,
),
{"comment": "Companies providing services for building"},
)
class BuildPersonProviding(CrudCollection):
"""
"""
""" """
__tablename__ = "build_person_providing"
__exclude__fields__ = []
__include__fields__ = []
build_id = mapped_column(ForeignKey("build.id"), nullable=False, comment="Building ID")
build_id = mapped_column(
ForeignKey("build.id"), nullable=False, comment="Building ID"
)
build_uu_id = mapped_column(String, nullable=True, comment="Providing UUID")
people_id = mapped_column(ForeignKey("people.id"))
people_id: Mapped[Identity] = mapped_column(ForeignKey("people.id"))
people_uu_id = mapped_column(String, nullable=True, comment="People UUID")
provide_id = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True)
provide_id: Mapped[Identity] = mapped_column(
ForeignKey("api_enum_dropdown.id"), nullable=True
)
provide_uu_id = mapped_column(String, nullable=True, comment="Providing UUID")
contract_id = mapped_column(Integer, ForeignKey('companies.id'), nullable=True)
contract_id = mapped_column(Integer, ForeignKey("companies.id"), nullable=True)
__table_args__ = (
Index("_build_person_providing_ndx_00", build_id, people_id, provide_id , unique=True),
Index(
"_build_person_providing_ndx_00",
build_id,
people_id,
provide_id,
unique=True,
),
{"comment": "People providing services for building"},
)
@@ -789,9 +836,9 @@ class BuildPersonProviding(CrudCollection):
# life_people: Mapped["People"] = relationship(
# "People", back_populates="life_living_spaces", foreign_keys=[life_person_id]
# )
# company_id = mapped_column(ForeignKey("companies.id"))
# response_company_id = mapped_column(ForeignKey("companies.id"))
# person_id = mapped_column(ForeignKey("people.id"))
# company_id: Mapped[Identity] = mapped_column(ForeignKey("companies.id"))
# response_company_id: Mapped[Identity] = mapped_column(ForeignKey("companies.id"))
# person_id: Mapped[Identity] = mapped_column(ForeignKey("people.id"))
# companies: Mapped["Companies"] = relationship(
# "Companies", back_populates="buildings", foreign_keys=[company_id]