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]

View File

@@ -8,11 +8,13 @@ from databases.sql_models.core_mixin import CrudCollection
from databases import (
Build,
BuildLivingSpace,
BuildIbans,
People,
BuildParts,
Companies,
OccupantTypes,
Services,
)
from api_library.date_time_actions.date_functions import DateTimeLocal
from api_library.date_time_actions.date_functions import system_arrow, client_arrow
from sqlalchemy import (
String,
@@ -24,10 +26,11 @@ from sqlalchemy import (
Text,
Numeric,
Integer,
Identity,
)
from sqlalchemy.orm import mapped_column, Mapped, relationship
from validations import (
from api_validations.validations_request import (
InsertDecisionBook,
InsertBuildDecisionBookItems,
InsertBuildDecisionBookItemDebits,
@@ -52,24 +55,34 @@ class BuildDecisionBook(CrudCollection):
__tablename__ = "build_decision_book"
__exclude__fields__ = []
decision_book_pdf_path = mapped_column(String)
resp_company_fix_wage = mapped_column(Numeric(10, 2), server_default="0") #
is_out_sourced = mapped_column(Boolean, server_default="0")
contact_id = mapped_column(ForeignKey("contracts.id"), nullable=True, comment="Contract id")
contact_uu_id = mapped_column(String, nullable=True, comment="Contract UUID")
meeting_date = mapped_column(TIMESTAMP, server_default="1900-01-01")
decision_type = mapped_column(String(3), server_default="RBM")
meeting_is_completed = mapped_column(Boolean, server_default="0")
meeting_completed_date = mapped_column(
decision_book_pdf_path: Mapped[str] = mapped_column(String)
resp_company_fix_wage: Mapped[float] = mapped_column(
Numeric(10, 2), server_default="0"
) #
is_out_sourced: Mapped[bool] = mapped_column(Boolean, server_default="0")
meeting_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, server_default="1900-01-01"
)
decision_type: Mapped[str] = mapped_column(String(3), server_default="RBM")
meeting_is_completed: Mapped[bool] = mapped_column(Boolean, server_default="0")
meeting_completed_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, nullable=True, comment="Meeting Completed Date"
)
build_id = mapped_column(ForeignKey("build.id"), nullable=False)
build_uu_id = mapped_column(String, nullable=True, comment="Build UUID")
resp_company_id = mapped_column(ForeignKey("companies.id"))
resp_company_uu_id = mapped_column(String, nullable=True, comment="Company UUID")
build_id: Mapped[Identity] = mapped_column(ForeignKey("build.id"), nullable=False)
build_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Build UUID"
)
resp_company_id: Mapped[Identity] = mapped_column(ForeignKey("companies.id"))
resp_company_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Company UUID"
)
contact_id: Mapped[Identity] = mapped_column(
ForeignKey("contracts.id"), nullable=True, comment="Contract id"
)
contact_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Contract UUID"
)
buildings: Mapped["Build"] = relationship(
"Build",
@@ -93,11 +106,11 @@ class BuildDecisionBook(CrudCollection):
@classmethod
def retrieve_active_rbm(cls):
related_build = Build.find_one(id=cls.build_id)
related_date = DateTimeLocal.get(str(related_build.build_date))
related_date = system_arrow.get(related_build.build_date)
date_processed = related_date.replace(
year=DateTimeLocal.now().date().year, month=related_date.month, day=1
year=system_arrow.now().date().year, month=related_date.month, day=1
)
if DateTimeLocal.now().date() <= date_processed:
if system_arrow.now().date() <= date_processed:
book = cls.filter_active(
cls.expiry_ends <= date_processed,
cls.decision_type == "RBM",
@@ -111,7 +124,6 @@ class BuildDecisionBook(CrudCollection):
@classmethod
def select_action(cls, duty_id, token=None):
from database_sql_models import Companies
related_companies = Companies.select_action(duty_id=duty_id)
related_companies_ids = list(
@@ -123,7 +135,6 @@ class BuildDecisionBook(CrudCollection):
@classmethod
def create_action(cls, data: InsertDecisionBook, token=None):
from database_sql_models import Build, Companies
data_dict = data.model_dump()
if building := Build.find_one(uu_id=data.build_uu_id):
@@ -137,25 +148,33 @@ class BuildDecisionBook(CrudCollection):
status_code=status.HTTP_406_NOT_ACCEPTABLE,
detail="Building must be given to create decision book.",
)
expiry_starts = datetime.strptime(
str(data_dict.get("expiry_starts")), "%Y-%m-%d"
expiry_starts = system_arrow.get(str(data_dict.get("expiry_starts"))).format(
"%Y-%m-%d"
)
expiry_ends = datetime.strptime(str(data_dict.get("expiry_ends")), "%Y-%m-%d")
data_dict["expiry_ends"] = expiry_ends.replace(
month=expiry_ends.month + 1, day=1
) - timedelta(days=1)
decision_book = BuildDecisionBook.filter_active(
data_dict["expiry_starts"] = str(expiry_starts)
expiry_ends = system_arrow.get(str(data_dict.get("expiry_ends"))).format(
"%Y-%m-%d"
)
data_dict["expiry_ends"] = str(
expiry_ends.replace(month=expiry_ends.month + 1, day=1) - timedelta(days=1)
)
if decision_book := BuildDecisionBook.filter_all(
BuildDecisionBook.build_id == building.id,
BuildDecisionBook.expiry_ends > data_dict["expiry_starts"],
BuildDecisionBook.decision_type == data_dict.get("decision_type"),
) # Decision book is already exist
if decision_book.count:
return
).count: # Decision book is already exist:
cls.raise_http_exception(
status_code=status.HTTP_409_CONFLICT,
error_case="RECORDEXITS",
message="Decision Book is already exist.",
data=decision_book.get_dict(),
)
data_dict["expiry_starts"] = expiry_starts.replace(day=1)
data_dict["expiry_ends"] = expiry_ends.replace(
month=expiry_ends.month + 1, day=1
) - timedelta(days=1)
data_dict["expiry_starts"] = str(expiry_starts.replace(day=1))
data_dict["expiry_ends"] = str(
expiry_ends.replace(month=expiry_ends.month + 1, day=1) - timedelta(days=1)
)
del data_dict["build_uu_id"], data_dict["resp_company_uu_id"]
return cls.find_or_create(**data_dict)
@@ -174,13 +193,15 @@ class BuildDecisionBook(CrudCollection):
[True if letter in str(bank_date) else False for letter in ["-", " ", ":"]]
):
bank_date = datetime.strptime(str(bank_date), "%Y-%m-%d %H:%M:%S")
date_valid = self.expiry_starts < bank_date < self.expiry_ends
date_valid = (
system_arrow.get(self.expiry_starts)
< system_arrow.get(bank_date)
< system_arrow.get(self.expiry_ends)
)
return date_valid and self.active and not self.deleted
@classmethod
def retrieve_valid_book(cls, bank_date, iban):
from database_sql_models import BuildIbans
if all(
[True if letter in str(bank_date) else False for letter in ["-", " ", ":"]]
):
@@ -206,19 +227,25 @@ class BuildDecisionBookInvitations(CrudCollection):
__tablename__ = "build_decision_book_invitations"
__exclude__fields__ = []
build_id = mapped_column(Integer, nullable=False)
build_uu_id = mapped_column(String, nullable=True, comment="Build UUID")
decision_book_id = mapped_column(
build_id: Mapped[int] = mapped_column(Integer, nullable=False)
build_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Build UUID"
)
decision_book_id: Mapped[Identity] = mapped_column(
ForeignKey("build_decision_book.id"), nullable=False
)
decision_book_uu_id = mapped_column(
decision_book_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Decision Book UUID"
)
invitation_type = mapped_column(String, nullable=False, comment="Invite Type")
invitation_attempt = mapped_column(SmallInteger, server_default="1")
living_part_count = mapped_column(SmallInteger, server_default="1")
living_part_percentage = mapped_column(Numeric(10, 2), server_default="0.51")
invitation_type: Mapped[str] = mapped_column(
String, nullable=False, comment="Invite Type"
)
invitation_attempt: Mapped[int] = mapped_column(SmallInteger, server_default="1")
living_part_count: Mapped[int] = mapped_column(SmallInteger, server_default="1")
living_part_percentage: Mapped[float] = mapped_column(
Numeric(10, 2), server_default="0.51"
)
message = mapped_column(Text, nullable=True, comment="Invitation Message")
planned_date = mapped_column(
@@ -299,7 +326,7 @@ class BuildDecisionBookPerson(CrudCollection):
__enum_list__ = [("management_typecode", "BuildManagementType", "bm")]
dues_percent_discount = mapped_column(SmallInteger, server_default="0")
dues_fix_discount = mapped_column(Numeric(10, 2), server_default="0")
dues_fix_discount: Mapped[float] = mapped_column(Numeric(10, 2), server_default="0")
dues_discount_approval_date = mapped_column(
TIMESTAMP, server_default="1900-01-01 00:00:00"
)
@@ -310,7 +337,9 @@ class BuildDecisionBookPerson(CrudCollection):
confirmed_date = mapped_column(
TIMESTAMP, nullable=True, comment="Confirmation Date"
)
token = mapped_column(String, server_default="", comment="Invitation Token")
token: Mapped[str] = mapped_column(
String, server_default="", comment="Invitation Token"
)
vicarious_person_id = mapped_column(
ForeignKey("people.id"), nullable=True, comment="Vicarious Person ID"
@@ -322,7 +351,9 @@ class BuildDecisionBookPerson(CrudCollection):
invite_id = mapped_column(
ForeignKey("build_decision_book_invitations.id"), nullable=False
)
invite_uu_id = mapped_column(String, nullable=False, comment="Invite UUID")
invite_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Invite UUID"
)
build_decision_book_id = mapped_column(
ForeignKey("build_decision_book.id"), nullable=False
@@ -336,8 +367,8 @@ class BuildDecisionBookPerson(CrudCollection):
build_living_space_uu_id = mapped_column(
String, nullable=True, comment="Living Space UUID"
)
person_id = mapped_column(ForeignKey("people.id"), nullable=False)
# person_uu_id = mapped_column(String, nullable=False, comment="Person UUID")
person_id: Mapped[Identity] = mapped_column(ForeignKey("people.id"), nullable=False)
# person_uu_id: Mapped[str] = mapped_column(String, nullable=False, comment="Person UUID")
__table_args__ = (
Index(
@@ -359,8 +390,9 @@ class BuildDecisionBookPerson(CrudCollection):
return BuildDecisionBookPersonOccupants.filter_active(filter_records=False)
def add_occupant_type(self, occupant_type, build_living_space_id: int = None):
from database_sql_models import Services
from events.events_bind_services import ServiceBindOccupantEventMethods
from api_events.events.events.events_bind_services import (
ServiceBindOccupantEventMethods,
)
book_dict = dict(
build_decision_book_person_id=self.id,
@@ -413,10 +445,10 @@ class BuildDecisionBookPerson(CrudCollection):
occupant_type_uu_id=str(occupant_type.uu_id),
person_id=living_space.person_id,
person_uu_id=str(living_space.person_uu_id),
expiry_starts=DateTimeLocal.get(
expiry_starts=system_arrow.get(
decision_book.meeting_date
).__str__(),
expiry_ends=DateTimeLocal.get(decision_book.meeting_date)
expiry_ends=system_arrow.get(decision_book.meeting_date)
.shift(hours=23)
.__str__(),
is_confirmed=True,
@@ -426,9 +458,7 @@ class BuildDecisionBookPerson(CrudCollection):
build_living_space_id=related_living_space.id,
service_id=related_service.id,
expires_at=str(
DateTimeLocal.get(decision_book.meeting_date).shift(
days=15
)
system_arrow.get(decision_book.meeting_date).shift(days=15)
),
)
return person_occupants
@@ -474,10 +504,16 @@ class BuildDecisionBookPersonOccupants(CrudCollection):
invite_id = mapped_column(
ForeignKey("build_decision_book_invitations.id"), nullable=True
)
invite_uu_id = mapped_column(String, nullable=True, comment="Invite UUID")
invite_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Invite UUID"
)
occupant_type_id = mapped_column(ForeignKey("occupant_types.id"), nullable=False)
occupant_type_uu_id = mapped_column(String, nullable=True, comment="Occupant UUID")
occupant_type_id: Mapped[Identity] = mapped_column(
ForeignKey("occupant_types.id"), nullable=False
)
occupant_type_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Occupant UUID"
)
__table_args__ = (
Index(
@@ -513,8 +549,12 @@ class BuildDecisionBookItems(CrudCollection):
Boolean, server_default="0", comment="Are payment Records Created"
)
info_type_id = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True)
info_type_uu_id = mapped_column(String, nullable=True, comment="Info Type UUID")
info_type_id: Mapped[Identity] = mapped_column(
ForeignKey("api_enum_dropdown.id"), nullable=True
)
info_type_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Info Type UUID"
)
build_decision_book_id = mapped_column(
ForeignKey("build_decision_book.id"), nullable=False
@@ -536,7 +576,6 @@ class BuildDecisionBookItems(CrudCollection):
@classmethod
def select_action(cls, duty_id, token=None):
from database_sql_models import Companies
related_companies = Companies.select_action(duty_id=duty_id)
related_companies_ids = list(
@@ -579,7 +618,6 @@ class BuildDecisionBookItems(CrudCollection):
@classmethod
def check_meeting_is_valid_to_start_add_attendance(cls, decision_book, token_dict):
from database_sql_models import OccupantTypes
active_invite = (
BuildDecisionBookInvitations.check_invites_are_ready_for_meeting(
@@ -728,8 +766,10 @@ class BuildDecisionBookItemsUnapproved(CrudCollection):
decision_book_item_uu_id = mapped_column(
String, nullable=True, comment="Decision Book Item"
)
person_id = mapped_column(ForeignKey("people.id"), nullable=False)
person_uu_id = mapped_column(String, nullable=True, comment="Person UUID")
person_id: Mapped[Identity] = mapped_column(ForeignKey("people.id"), nullable=False)
person_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Person UUID"
)
build_decision_book_item = mapped_column(
ForeignKey("build_decision_book_items.id"), nullable=False
)
@@ -762,14 +802,18 @@ class BuildDecisionBookPayments(CrudCollection):
payment_amount = mapped_column(
Numeric(16, 2), nullable=False, comment="Payment Amount"
)
currency = mapped_column(String(8), server_default="TRY")
currency: Mapped[str] = mapped_column(String(8), server_default="TRY")
payment_types_id = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True)
payment_types_uu_id = mapped_column(String, nullable=True, comment="Dues Type UUID")
payment_types_id: Mapped[Identity] = mapped_column(
ForeignKey("api_enum_dropdown.id"), nullable=True
)
payment_types_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Dues Type UUID"
)
period_time = mapped_column(String(12))
process_date_y = mapped_column(SmallInteger)
process_date_m = mapped_column(SmallInteger)
period_time: Mapped[str] = mapped_column(String(12))
process_date_y: Mapped[int] = mapped_column(SmallInteger)
process_date_m: Mapped[int] = mapped_column(SmallInteger)
build_decision_book_item_id = mapped_column(
ForeignKey("build_decision_book_items.id"),
@@ -780,21 +824,33 @@ class BuildDecisionBookPayments(CrudCollection):
String, nullable=True, comment="Decision Book Item UUID"
)
decision_book_project_id = mapped_column(
ForeignKey("build_decision_book_projects.id"), nullable=True, comment="Decision Book Project ID"
ForeignKey("build_decision_book_projects.id"),
nullable=True,
comment="Decision Book Project ID",
)
decision_book_project_uu_id = mapped_column(
String, nullable=True, comment="Decision Book Project UUID"
)
build_parts_id = mapped_column(ForeignKey("build_parts.id"), nullable=False)
build_parts_uu_id = mapped_column(String, nullable=True, comment="Build Part UUID")
build_parts_id: Mapped[Identity] = mapped_column(
ForeignKey("build_parts.id"), nullable=False
)
build_parts_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Build Part UUID"
)
budget_records_id = mapped_column(ForeignKey("account_records.id"))
budget_records_uu_id = mapped_column(String, nullable=True, comment="Budget UUID")
accounting_id = mapped_column(ForeignKey("account_detail.id"))
accounting_uu_id = mapped_column(String, nullable=True, comment="Accounting UUID")
# receive_debit_id = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True)
# receive_debit_uu_id = mapped_column(String, nullable=True, comment="Debit UUID")
budget_records_id: Mapped[Identity] = mapped_column(
ForeignKey("account_records.id")
)
budget_records_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Budget UUID"
)
accounting_id: Mapped[Identity] = mapped_column(ForeignKey("account_detail.id"))
accounting_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Accounting UUID"
)
# receive_debit_id: Mapped[Identity] = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True)
# receive_debit_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Debit UUID")
# accounting: Mapped["AccountDetail"] = relationship(
# "AccountDetail",
@@ -851,8 +907,10 @@ class BuildDecisionBookLegal(CrudCollection):
)
period_stop_date = mapped_column(TIMESTAMP, server_default="2099-12-31 23:59:59")
decision_book_pdf_path = mapped_column(String(128))
resp_company_total_wage = mapped_column(Numeric(10, 2), server_default="0")
decision_book_pdf_path: Mapped[str] = mapped_column(String(128))
resp_company_total_wage: Mapped[float] = mapped_column(
Numeric(10, 2), server_default="0"
)
contact_agreement_path = mapped_column(String(128))
contact_agreement_date = mapped_column(
TIMESTAMP, server_default="1900-01-01 00:00:00"
@@ -861,12 +919,12 @@ class BuildDecisionBookLegal(CrudCollection):
lawsuits_type = mapped_column(String(1), server_default="C")
lawsuits_name = mapped_column(String(128))
lawsuits_note = mapped_column(String(512))
lawyer_cost = mapped_column(Numeric(20, 2))
mediator_lawyer_cost = mapped_column(Numeric(20, 2))
other_cost = mapped_column(Numeric(20, 2))
legal_cost = mapped_column(Numeric(20, 2))
approved_cost = mapped_column(Numeric(20, 2))
total_price = mapped_column(Numeric(20, 2))
lawyer_cost: Mapped[float] = mapped_column(Numeric(20, 2))
mediator_lawyer_cost: Mapped[float] = mapped_column(Numeric(20, 2))
other_cost: Mapped[float] = mapped_column(Numeric(20, 2))
legal_cost: Mapped[float] = mapped_column(Numeric(20, 2))
approved_cost: Mapped[float] = mapped_column(Numeric(20, 2))
total_price: Mapped[float] = mapped_column(Numeric(20, 2))
build_db_item_id = mapped_column(
ForeignKey("build_decision_book_items.id"), nullable=False
@@ -874,13 +932,17 @@ class BuildDecisionBookLegal(CrudCollection):
build_db_item_uu_id = mapped_column(
String, nullable=True, comment="Decision Book Item UUID"
)
resp_attorney_id = mapped_column(ForeignKey("people.id"), nullable=False)
resp_attorney_id: Mapped[Identity] = mapped_column(
ForeignKey("people.id"), nullable=False
)
resp_attorney_uu_id = mapped_column(String, nullable=True, comment="Attorney UUID")
resp_attorney_company_id = mapped_column(ForeignKey("companies.id"))
resp_attorney_company_id: Mapped[Identity] = mapped_column(
ForeignKey("companies.id")
)
resp_attorney_company_uu_id = mapped_column(
String, nullable=True, comment="Company UUID"
)
mediator_lawyer_person_id = mapped_column(ForeignKey("people.id"))
mediator_lawyer_person_id: Mapped[Identity] = mapped_column(ForeignKey("people.id"))
mediator_lawyer_person_uu_id = mapped_column(
String, nullable=True, comment="Mediator Lawyer UUID"
)
@@ -902,7 +964,9 @@ class BuildDecisionBookProjects(CrudCollection):
__tablename__ = "build_decision_book_projects"
__exclude__fields__ = []
project_no = mapped_column(String(12), nullable=True, comment="Project Number of Decision Book")
project_no = mapped_column(
String(12), nullable=True, comment="Project Number of Decision Book"
)
project_name = mapped_column(String, nullable=False, comment="Project Name")
project_start_date = mapped_column(
TIMESTAMP, nullable=False, comment="Project Start Date"
@@ -914,33 +978,45 @@ class BuildDecisionBookProjects(CrudCollection):
decision_book_pdf_path = mapped_column(String)
resp_company_fix_wage = mapped_column(Numeric(10, 2), server_default="0")
is_out_sourced = mapped_column(Boolean, server_default="0")
contact_id = mapped_column(ForeignKey("contracts.id"), nullable=True, comment="Contract id")
resp_company_fix_wage: Mapped[float] = mapped_column(
Numeric(10, 2), server_default="0"
)
is_out_sourced: Mapped[bool] = mapped_column(Boolean, server_default="0")
contact_id = mapped_column(
ForeignKey("contracts.id"), nullable=True, comment="Contract id"
)
contact_uu_id = mapped_column(String, nullable=True, comment="Contract UUID")
meeting_date = mapped_column(
TIMESTAMP, server_default="1900-01-01 00:00:00", index=True
)
currency = mapped_column(String(8), server_default="TRY")
bid_price = mapped_column(Numeric(16, 4), server_default="0")
approved_price = mapped_column(Numeric(16, 4), server_default="0")
final_price = mapped_column(Numeric(16, 4), server_default="0")
bid_price: Mapped[float] = mapped_column(Numeric(16, 4), server_default="0")
approved_price: Mapped[float] = mapped_column(Numeric(16, 4), server_default="0")
final_price: Mapped[float] = mapped_column(Numeric(16, 4), server_default="0")
build_decision_book_id = mapped_column(ForeignKey("build_decision_book.id"), nullable=False)
build_decision_book_id = mapped_column(
ForeignKey("build_decision_book.id"), nullable=False
)
build_decision_book_uu_id = mapped_column(
String, nullable=True, comment="Decision Book UUID"
)
build_decision_book_item_id = mapped_column(ForeignKey("build_decision_book_items.id"), nullable=False)
build_decision_book_item_id = mapped_column(
ForeignKey("build_decision_book_items.id"), nullable=False
)
build_decision_book_item_uu_id = mapped_column(
String, nullable=True, comment="Decision Book Item UUID"
)
project_response_living_space_id = mapped_column(
ForeignKey("build_living_space.id"), nullable=True, comment="Project Response Person ID"
ForeignKey("build_living_space.id"),
nullable=True,
comment="Project Response Person ID",
)
project_response_living_space_uu_id = mapped_column(
String, nullable=True, comment="Project Response Person UUID"
)
resp_company_id = mapped_column(ForeignKey("companies.id"), nullable=True)
resp_company_id: Mapped[Identity] = mapped_column(
ForeignKey("companies.id"), nullable=True
)
resp_company_uu_id = mapped_column(String, nullable=True, comment="Company UUID")
build_decision_book_item: Mapped["BuildDecisionBookItems"] = relationship(
@@ -951,11 +1027,6 @@ class BuildDecisionBookProjects(CrudCollection):
@classmethod
def select_action(cls, duty_id, token=None):
from database_sql_models import (
Companies,
BuildDecisionBook,
BuildDecisionBookItems,
)
related_companies = Companies.select_action(duty_id=duty_id)
related_companies_ids = list(
@@ -983,8 +1054,6 @@ class BuildDecisionBookProjects(CrudCollection):
@classmethod
def create_action(cls, data: InsertBuildDecisionBookProjects, token=None):
from database_sql_models import People, BuildDecisionBookItems, Companies
data_dict = data.dump()
BuildDecisionBookItems.pre_query = BuildDecisionBookItems.select_action(
duty_id=token.duty_list["duty_id"]
@@ -1040,9 +1109,9 @@ class BuildDecisionBookProjectPerson(CrudCollection):
__enum_list__ = [("management_typecode", "ProjectTeamTypes", "PTT-EMP")]
dues_percent_discount = mapped_column(SmallInteger, server_default="0")
job_fix_wage = mapped_column(Numeric(10, 2), server_default="0")
bid_price = mapped_column(Numeric(10, 2), server_default="0")
decision_price = mapped_column(Numeric(10, 2), server_default="0")
job_fix_wage: Mapped[float] = mapped_column(Numeric(10, 2), server_default="0")
bid_price: Mapped[float] = mapped_column(Numeric(10, 2), server_default="0")
decision_price: Mapped[float] = mapped_column(Numeric(10, 2), server_default="0")
build_decision_book_project_id = mapped_column(
ForeignKey("build_decision_book_projects.id"), nullable=False
@@ -1050,8 +1119,12 @@ class BuildDecisionBookProjectPerson(CrudCollection):
build_decision_book_project_uu_id = mapped_column(
String, nullable=True, comment="Decision Book Project UUID"
)
living_space_id = mapped_column(ForeignKey("build_living_space.id"), nullable=False)
living_space_uu_id = mapped_column(String, nullable=True, comment="Living Space UUID")
living_space_id: Mapped[Identity] = mapped_column(
ForeignKey("build_living_space.id"), nullable=False
)
living_space_uu_id = mapped_column(
String, nullable=True, comment="Living Space UUID"
)
project_team_type_id = mapped_column(
ForeignKey("api_enum_dropdown.id"), nullable=True
@@ -1082,7 +1155,7 @@ class BuildDecisionBookProjectPerson(CrudCollection):
# Numeric(20, 2), nullable=False, comment="Default Payment Amount"
# )
#
# dues_types_id = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True)
# dues_types_id: Mapped[Identity] = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True)
# dues_types_uu_id = mapped_column(String, nullable=True, comment="Dues Type UUID")
# build_decision_book_item_debits_id = mapped_column(
# ForeignKey("build_decision_book_item_debits.id"), nullable=False
@@ -1090,7 +1163,7 @@ class BuildDecisionBookProjectPerson(CrudCollection):
# build_decision_book_item_debits_uu_id = mapped_column(
# String, nullable=True, comment="Decision Book Item Debit UUID"
# )
# build_parts_id = mapped_column(ForeignKey("build_parts.id"), nullable=False)
# build_parts_id: Mapped[Identity] = mapped_column(ForeignKey("build_parts.id"), nullable=False)
# build_parts_uu_id = mapped_column(String, nullable=True, comment="Build Part UUID")
#
# # decision_books_item_debits: Mapped["BuildDecisionBookItemDebits"] = relationship(
@@ -1219,7 +1292,7 @@ class BuildDecisionBookProjectPerson(CrudCollection):
# __exclude__fields__ = []
# __enum_list__ = [("dues_types", "BuildDuesTypes", "D")]
#
# dues_types_id = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True)
# dues_types_id: Mapped[Identity] = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True)
# dues_types_uu_id = mapped_column(String, nullable=True, comment="Dues Type UUID")
# # dues_values = mapped_column(
# # MutableDict.as_mutable(JSONB()),
@@ -1232,7 +1305,7 @@ class BuildDecisionBookProjectPerson(CrudCollection):
# flat_payment = mapped_column(
# Numeric(20, 2), nullable=True, comment="Flat Payment Amount"
# )
# decision_taken = mapped_column(Boolean, server_default="0")
# decision_taken: Mapped[bool] = mapped_column(Boolean, server_default="0")
#
# build_decision_book_item_id = mapped_column(
# ForeignKey("build_decision_book_items.id"), nullable=False
@@ -1350,15 +1423,15 @@ class BuildDecisionBookProjectPerson(CrudCollection):
#
# item_order = mapped_column(SmallInteger, nullable=False, comment="Order Number")
# budget_type = mapped_column(String, nullable=False, comment="Budget Type")
# plan_value = mapped_column(Numeric(10, 2), nullable=False, comment="Plan Value")
# plan_value: Mapped[float] = mapped_column(Numeric(10, 2), nullable=False, comment="Plan Value")
#
# line_comment = mapped_column(String(32), server_default="")
# process_date_y = mapped_column(SmallInteger)
# process_date_m = mapped_column(SmallInteger)
# process_date_w = mapped_column(SmallInteger)
# process_date_y: Mapped[int] = mapped_column(SmallInteger)
# process_date_m: Mapped[int] = mapped_column(SmallInteger)
# process_date_w: Mapped[int] = mapped_column(SmallInteger)
# period_time = mapped_column(String(12), server_default="")
#
# build_decision_book_id = mapped_column(ForeignKey("build_decision_book.id"))
# build_decision_book_id: Mapped[Identity] = mapped_column(ForeignKey("build_decision_book.id"))
# accounting_id = mapped_column(ForeignKey("account_detail.id"))
#
# __table_args__ = (
@@ -1377,7 +1450,7 @@ class BuildDecisionBookProjectPerson(CrudCollection):
#
# paid_date = mapped_column(TIMESTAMP, nullable=False, comment="Payment Due Date")
# period_time = mapped_column(String(12), server_default="")
# paid_value = mapped_column(Numeric(10, 2), server_default="0")
# paid_value: Mapped[float] = mapped_column(Numeric(10, 2), server_default="0")
#
# build_decision_book_budget_id = mapped_column(
# ForeignKey("build_decision_book_budget.id"), nullable=False
@@ -1566,7 +1639,7 @@ class BuildDecisionBookProjectPerson(CrudCollection):
# person_uu_id = mapped_column(String, nullable=False, comment="Person UUID")
#
# send_date = mapped_column(TIMESTAMP, nullable=False, comment="Confirmation Date")
# is_confirmed = mapped_column(Boolean, server_default="0", comment="Message is Confirmed")
# is_confirmed: Mapped[bool] = mapped_column(Boolean, server_default="0", comment="Message is Confirmed")
# confirmed_date = mapped_column(TIMESTAMP, nullable=True, comment="Confirmation Date")
# token = mapped_column(String, server_default="", comment="Invitation Token")
#