services are checked
This commit is contained in:
@@ -11,9 +11,7 @@ from databases.sql_models.account.iban import (
|
||||
BuildIbans,
|
||||
BuildIbanDescription,
|
||||
)
|
||||
from databases.sql_models.api.encrypter import (
|
||||
CrypterEngine
|
||||
)
|
||||
from databases.sql_models.api.encrypter import CrypterEngine
|
||||
from databases.sql_models.building.build import (
|
||||
Build,
|
||||
BuildTypes,
|
||||
@@ -86,7 +84,7 @@ from databases.sql_models.rules.rules import (
|
||||
EndpointRestriction,
|
||||
)
|
||||
|
||||
#NO-SQL Models
|
||||
# NO-SQL Models
|
||||
from databases.no_sql_models.mongo_database import (
|
||||
MongoQuery,
|
||||
)
|
||||
@@ -161,5 +159,3 @@ __all__ = [
|
||||
"MongoQuery",
|
||||
"MongoQueryIdentity",
|
||||
]
|
||||
|
||||
|
||||
|
||||
11
databases/extensions/__init__.py
Normal file
11
databases/extensions/__init__.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from .selector_classes import (
|
||||
Explanation,
|
||||
SelectActionWithEmployee,
|
||||
SelectAction,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Explanation",
|
||||
"SelectAction",
|
||||
"SelectActionWithEmployee",
|
||||
]
|
||||
351
databases/extensions/auth.py
Normal file
351
databases/extensions/auth.py
Normal file
@@ -0,0 +1,351 @@
|
||||
import uuid
|
||||
import secrets
|
||||
import hashlib
|
||||
import requests
|
||||
|
||||
from sqlalchemy import or_
|
||||
from datetime import timedelta
|
||||
from fastapi.exceptions import HTTPException
|
||||
from fastapi import status
|
||||
|
||||
from databases import (
|
||||
Users,
|
||||
People,
|
||||
Companies,
|
||||
UsersTokens,
|
||||
MongoQueryIdentity,
|
||||
)
|
||||
from databases.no_sql_models.validations import (
|
||||
PasswordHistoryViaUser,
|
||||
AccessHistoryViaUser,
|
||||
)
|
||||
|
||||
from api_library.date_time_actions.date_functions import system_arrow, client_arrow
|
||||
from api_configs import ApiStatic, Auth
|
||||
|
||||
from api_services.redis.auth_actions.auth import save_access_token_to_redis
|
||||
|
||||
|
||||
class PasswordModule:
|
||||
|
||||
@classmethod
|
||||
def generate_token(cls, length):
|
||||
return secrets.token_urlsafe(length)
|
||||
|
||||
@classmethod
|
||||
def create_hashed_password(cls, domain, id_, password):
|
||||
salted_password = f"{domain}-{id_}-{password}"
|
||||
return hashlib.sha256(salted_password.encode()).hexdigest()
|
||||
|
||||
@classmethod
|
||||
def check_hashed_password(cls, domain, id_, password, password_hashed):
|
||||
return cls.create_hashed_password(domain, id_, password) == password_hashed
|
||||
|
||||
|
||||
class AuthModule(PasswordModule):
|
||||
|
||||
@classmethod
|
||||
def check_user_exits(cls, access_key, domain):
|
||||
|
||||
found_user: Users = cls.filter_active(
|
||||
or_(
|
||||
cls.email == str(access_key).lower(),
|
||||
cls.phone_number == str(access_key).replace(" ", ""),
|
||||
),
|
||||
filter_records=False,
|
||||
)
|
||||
if not found_user.data:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Given access key or domain is not matching with the any user record.",
|
||||
)
|
||||
found_user = found_user.data[0]
|
||||
other_domains_list = found_user.get_main_domain_and_other_domains(
|
||||
get_main_domain=False
|
||||
)
|
||||
|
||||
if domain not in other_domains_list:
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail=dict(message="Unauthorized User attempts to connect api"),
|
||||
)
|
||||
|
||||
if not found_user:
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail="Given access key or domain is not matching with the any user record.",
|
||||
)
|
||||
return found_user
|
||||
|
||||
def generate_access_token(self):
|
||||
return self.generate_token(Auth.ACCESS_TOKEN_LENGTH)
|
||||
|
||||
def remove_refresher_token(self, domain, disconnect: bool = False):
|
||||
registered_tokens = ([], 0)
|
||||
if disconnect:
|
||||
registered_tokens = UsersTokens.filter_by(user_id=self.id)
|
||||
else:
|
||||
registered_tokens = UsersTokens.filter_by(domain=domain, user_id=self.id)
|
||||
for token in registered_tokens[0]:
|
||||
token.session.delete(token)
|
||||
token.session.commit()
|
||||
token.session.flush()
|
||||
|
||||
def check_password(self, password):
|
||||
main_domain = self.get_main_domain_and_other_domains(get_main_domain=True)
|
||||
if check_password := self.check_hashed_password(
|
||||
domain=main_domain,
|
||||
id_=self.uu_id,
|
||||
password_hashed=self.hash_password,
|
||||
password=password,
|
||||
):
|
||||
return check_password
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail="Password is not correct.",
|
||||
)
|
||||
|
||||
def check_password_is_different(self, password):
|
||||
main_domain = self.get_main_domain_and_other_domains(get_main_domain=True)
|
||||
if self.hash_password == self.create_hashed_password(
|
||||
domain=main_domain, id_=self.uu_id, password=password
|
||||
):
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail="New password is same with old password.",
|
||||
)
|
||||
|
||||
def create_password(self, password, password_token=None):
|
||||
if self.password_token:
|
||||
replace_day = 0
|
||||
try:
|
||||
replace_day = int(
|
||||
str(self.password_expires_day or 0)
|
||||
.split(",")[0]
|
||||
.replace(" days", "")
|
||||
)
|
||||
except Exception as e:
|
||||
err = e
|
||||
token_is_expired = system_arrow.now() >= system_arrow.get(
|
||||
self.password_expiry_begins
|
||||
).shift(days=replace_day)
|
||||
|
||||
if not password_token == self.password_token and token_is_expired:
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail="Password token is not valid. Please request a new password token.",
|
||||
)
|
||||
|
||||
query_engine = MongoQueryIdentity(company_uuid=self.related_company)
|
||||
domain_via_user = query_engine.get_domain_via_user(user_uu_id=str(self.uu_id))[
|
||||
"main_domain"
|
||||
]
|
||||
new_password_dict = {
|
||||
"password": self.create_hashed_password(
|
||||
domain=domain_via_user, id_=self.uu_id, password=password
|
||||
),
|
||||
"date": str(system_arrow.now()),
|
||||
}
|
||||
history_dict = PasswordHistoryViaUser(
|
||||
user_uu_id=str(self.uu_id),
|
||||
password_add=new_password_dict,
|
||||
access_history_detail={
|
||||
"request": "",
|
||||
"ip": "",
|
||||
},
|
||||
)
|
||||
query_engine.refresh_password_history_via_user(payload=history_dict)
|
||||
self.password_expiry_begins = str(system_arrow.now())
|
||||
self.hash_password = new_password_dict.get("password")
|
||||
if self.password_token:
|
||||
self.password_token = None
|
||||
self.save()
|
||||
|
||||
def reset_password_token(self):
|
||||
self.password_expiry_begins = str(system_arrow.now())
|
||||
self.password_token = self.generate_token(127)
|
||||
self.save()
|
||||
|
||||
def generate_refresher_token(self, domain: str, remember_me=False):
|
||||
if remember_me:
|
||||
refresh_token = self.generate_token(Auth.REFRESHER_TOKEN_LENGTH)
|
||||
if already_token := UsersTokens.find_one(
|
||||
user_id=self.id, token_type="RememberMe", domain=domain
|
||||
):
|
||||
already_token.update(token=refresh_token)
|
||||
already_token.expires_at = system_arrow.shift(days=3)
|
||||
already_token.save()
|
||||
return refresh_token
|
||||
UsersTokens.create(
|
||||
user_id=self.id,
|
||||
token_type="RememberMe",
|
||||
token=refresh_token,
|
||||
domain=domain,
|
||||
)
|
||||
return refresh_token
|
||||
return None
|
||||
|
||||
def remainder_day(self):
|
||||
return float(
|
||||
timedelta(
|
||||
days=int(
|
||||
"".join(
|
||||
[
|
||||
_
|
||||
for _ in str(self.password_expires_day).split(",")[0]
|
||||
if _.isdigit()
|
||||
]
|
||||
)
|
||||
)
|
||||
).seconds
|
||||
)
|
||||
|
||||
|
||||
class UserLoginModule(AuthModule):
|
||||
|
||||
@classmethod
|
||||
def login_user_with_credentials(cls, data, request):
|
||||
|
||||
found_user = Users.check_user_exits(
|
||||
access_key=data.access_key, domain=data.domain
|
||||
)
|
||||
access_token = found_user.generate_access_token()
|
||||
query_engine = MongoQueryIdentity(company_uuid=found_user.related_company)
|
||||
|
||||
if found_user.check_password(password=data.password):
|
||||
access_object_to_redis = save_access_token_to_redis(
|
||||
request=request,
|
||||
found_user=found_user,
|
||||
domain=data.domain,
|
||||
access_token=access_token,
|
||||
)
|
||||
refresher_token = found_user.generate_refresher_token(
|
||||
domain=data.domain, remember_me=data.remember_me
|
||||
)
|
||||
headers_request = request.headers
|
||||
headers_request = dict(headers_request)
|
||||
headers_request["evyos-user-agent"] = headers_request.get("user-agent")
|
||||
headers_request["evyos-platform"] = headers_request.get("user-agent")
|
||||
headers_request["evyos-ip-ext"] = "94.54.68.158"
|
||||
found_user.last_agent = headers_request.get("evyos-user-agent", None)
|
||||
found_user.last_platform = headers_request.get("evyos-platform", None)
|
||||
found_user.last_remote_addr = headers_request.get("evyos-ip-ext", None)
|
||||
found_user.last_seen = str(system_arrow.now())
|
||||
|
||||
if ext_ip := headers_request.get("evyos-ip-ext"):
|
||||
agent = headers_request.get("evyos-user-agent", "")
|
||||
platform = headers_request.get("evyos-platform", "")
|
||||
address = requests.get(f"http://ip-api.com/json/{ext_ip}").json()
|
||||
address_package = {
|
||||
"city": address["city"],
|
||||
"zip": address["zip"],
|
||||
"country": address["country"],
|
||||
"countryCode": address["countryCode"],
|
||||
"region": address["region"],
|
||||
"regionName": address["regionName"],
|
||||
}
|
||||
mongo_db = MongoQueryIdentity(
|
||||
company_uuid=str(found_user.related_company).replace(" ", ""),
|
||||
storage_reasoning="AccessHistory",
|
||||
)
|
||||
filter_query = {
|
||||
"agent": agent,
|
||||
"platform": platform,
|
||||
"address": address_package,
|
||||
"user_id": found_user.id,
|
||||
}
|
||||
already_exits = mongo_db.mongo_engine.filter_by(filter_query) or None
|
||||
no_address_validates = mongo_db.mongo_engine.get_all()[0] == 0
|
||||
record_id = uuid.uuid4().__str__()
|
||||
notice_link = ApiStatic.blacklist_login(record_id=record_id)
|
||||
found_people = People.find_one(id=found_user.person_id)
|
||||
access_via_user = query_engine.update_access_history_via_user(
|
||||
AccessHistoryViaUser(
|
||||
**{
|
||||
"user_uu_id": found_user.uu_id.__str__(),
|
||||
"access_history": {
|
||||
"record_id": record_id,
|
||||
"agent": agent,
|
||||
"platform": platform,
|
||||
"address": address_package,
|
||||
"ip": ext_ip,
|
||||
"access_token": access_token,
|
||||
"created_at": system_arrow.now().timestamp(),
|
||||
# "is_confirmed": True if no_address_validates else False,
|
||||
# "is_first": True if no_address_validates else False,
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
if already_exits:
|
||||
update_mongo = mongo_db.mongo_engine.table.update_one(
|
||||
filter=filter_query,
|
||||
update={
|
||||
"$set": {
|
||||
"ip": ext_ip,
|
||||
"access_token": access_token,
|
||||
"created_at": system_arrow.now().timestamp(),
|
||||
}
|
||||
},
|
||||
)
|
||||
else:
|
||||
mongo_db.mongo_engine.insert(
|
||||
payload={
|
||||
"user_id": found_user.id,
|
||||
"record_id": record_id,
|
||||
"agent": agent,
|
||||
"platform": platform,
|
||||
"address": address_package,
|
||||
"ip": ext_ip,
|
||||
"access_token": access_token,
|
||||
"created_at": system_arrow.now().timestamp(),
|
||||
"is_confirmed": True if no_address_validates else False,
|
||||
"is_first": True if no_address_validates else False,
|
||||
}
|
||||
)
|
||||
found_user.remember_me = bool(data.remember_me)
|
||||
found_user.save()
|
||||
return {
|
||||
"access_token": access_token,
|
||||
"refresher_token": refresher_token,
|
||||
"user": found_user,
|
||||
"access_object": access_object_to_redis,
|
||||
}
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail="Login is not successful. Please check your credentials.",
|
||||
)
|
||||
|
||||
|
||||
# UserLogger.log_error(
|
||||
# dict(
|
||||
# user_id=found_user.id,
|
||||
# domain=data.domain,
|
||||
# access_key=data.access_key,
|
||||
# agent=found_user.last_agent,
|
||||
# ip=getattr(request, "remote_addr", None)
|
||||
# or request.headers.get("X-Forwarded-For", None),
|
||||
# platform=found_user.last_platform,
|
||||
# login_date=str(DateTimeLocal.now()),
|
||||
# is_login=True,
|
||||
# )
|
||||
# )
|
||||
|
||||
# if (
|
||||
# not str(found_people.country_code).lower()
|
||||
# == str(address_package.get("countryCode")).lower()
|
||||
# ):
|
||||
# send_email_completed = send_email(
|
||||
# subject=f"Dear {found_user.nick_name}, your password has been changed.",
|
||||
# receivers=[str(found_user.email)],
|
||||
# html=invalid_ip_or_address_found(
|
||||
# user_name=found_user.nick_name,
|
||||
# address=address_package,
|
||||
# notice_link=notice_link,
|
||||
# ),
|
||||
# )
|
||||
# if not send_email_completed:
|
||||
# raise HTTPException(
|
||||
# status_code=400,
|
||||
# detail="An error occured at sending email. Please contact with support team.",
|
||||
# )
|
||||
79
databases/extensions/selector_classes.py
Normal file
79
databases/extensions/selector_classes.py
Normal file
@@ -0,0 +1,79 @@
|
||||
class Explanation: ...
|
||||
|
||||
|
||||
class SelectorsBase:
|
||||
@classmethod
|
||||
def add_confirmed_filter(cls, first_table, second_table) -> tuple:
|
||||
return (
|
||||
first_table.active == True,
|
||||
first_table.is_confirmed == True,
|
||||
first_table.deleted == False,
|
||||
second_table.active == True,
|
||||
second_table.is_confirmed == True,
|
||||
second_table.deleted == False,
|
||||
)
|
||||
|
||||
|
||||
class SelectActionWithEmployee:
|
||||
|
||||
@classmethod
|
||||
def select_action(cls, employee_id, filter_expr: list = None):
|
||||
if filter_expr is not None:
|
||||
filter_expr = (cls.__many__table__.employee_id == employee_id, *filter_expr)
|
||||
data = (
|
||||
cls.session.query(cls.id)
|
||||
.select_from(cls)
|
||||
.join(cls.__many__table__, cls.__many__table__.member_id == cls.id)
|
||||
.filter(
|
||||
*filter_expr,
|
||||
*SelectorsBase.add_confirmed_filter(
|
||||
first_table=cls, second_table=cls.__many__table__
|
||||
),
|
||||
)
|
||||
)
|
||||
return cls.query.filter(cls.id.in_([comp[0] for comp in data.all()]))
|
||||
data = (
|
||||
cls.session.query(cls.id)
|
||||
.select_from(cls)
|
||||
.join(cls.__many__table__, cls.__many__table__.member_id == cls.id)
|
||||
.filter(
|
||||
cls.__many__table__.employee_id == employee_id,
|
||||
*SelectorsBase.add_confirmed_filter(
|
||||
first_table=cls, second_table=cls.__many__table__
|
||||
),
|
||||
)
|
||||
)
|
||||
return cls.query.filter(cls.id.in_([comp[0] for comp in data.all()]))
|
||||
|
||||
|
||||
class SelectAction:
|
||||
|
||||
@classmethod
|
||||
def select_action(cls, duty_id_list: list, filter_expr: list = None):
|
||||
if filter_expr is not None:
|
||||
data = (
|
||||
cls.session.query(cls.id)
|
||||
.select_from(cls)
|
||||
.join(cls.__many__table__, cls.__many__table__.member_id == cls.id)
|
||||
.filter(
|
||||
cls.__many__table__.duties_id.in_(duty_id_list),
|
||||
*SelectorsBase.add_confirmed_filter(
|
||||
first_table=cls, second_table=cls.__many__table__
|
||||
),
|
||||
*filter_expr,
|
||||
)
|
||||
)
|
||||
return cls.query.filter(cls.id.in_([comp[0] for comp in data.all()]))
|
||||
|
||||
data = (
|
||||
cls.session.query(cls.id)
|
||||
.select_from(cls)
|
||||
.join(cls.__many__table__, cls.__many__table__.member_id == cls.id)
|
||||
.filter(
|
||||
cls.__many__table__.duties_id.in_(duty_id_list)
|
||||
* SelectorsBase.add_confirmed_filter(
|
||||
first_table=cls, second_table=cls.__many__table__
|
||||
),
|
||||
)
|
||||
)
|
||||
return cls.query.filter(cls.id.in_([comp[0] for comp in data.all()]))
|
||||
@@ -36,8 +36,7 @@ def load_user_with_erp_details(found_user, access_dict: dict = None):
|
||||
# }
|
||||
# )
|
||||
err = e
|
||||
print('MongoQuery load_user_with_erp_details', err)
|
||||
|
||||
print("MongoQuery load_user_with_erp_details", err)
|
||||
|
||||
for building in list(set(employee.duty.department.company.response_buildings)):
|
||||
build_parts = []
|
||||
|
||||
@@ -8,6 +8,7 @@ from api_configs import MongoConfig
|
||||
from pymongo import MongoClient
|
||||
from pymongo.collection import Collection
|
||||
from pymongo.results import InsertManyResult
|
||||
|
||||
# from configs import TestMongo as MongoConfig
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from databases.sql_models.core_mixin import CrudCollection
|
||||
|
||||
from sqlalchemy.orm import mapped_column
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from sqlalchemy import (
|
||||
String,
|
||||
Integer,
|
||||
@@ -10,6 +10,8 @@ from sqlalchemy import (
|
||||
Boolean,
|
||||
TIMESTAMP,
|
||||
Numeric,
|
||||
Identity,
|
||||
UUID,
|
||||
)
|
||||
|
||||
|
||||
@@ -18,15 +20,15 @@ class AccountBooks(CrudCollection):
|
||||
__tablename__ = "account_books"
|
||||
__exclude__fields__ = []
|
||||
|
||||
country = mapped_column(String, nullable=False)
|
||||
branch_type = mapped_column(SmallInteger, server_default="0")
|
||||
# start_date = mapped_column(TIMESTAMP, nullable=False, comment="Account Start Date")
|
||||
# stop_date = mapped_column(TIMESTAMP, server_default="2900-01-01 00:00:00")
|
||||
country: Mapped[str] = mapped_column(String, nullable=False)
|
||||
branch_type: Mapped[str] = mapped_column(SmallInteger, server_default="0")
|
||||
|
||||
company_id = mapped_column(ForeignKey("companies.id"), nullable=False)
|
||||
company_uu_id = mapped_column(String, nullable=False)
|
||||
branch_id = mapped_column(ForeignKey("companies.id"))
|
||||
branch_uu_id = mapped_column(String, comment="Branch UU ID")
|
||||
company_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("companies.id"), nullable=False
|
||||
)
|
||||
company_uu_id: Mapped[UUID] = mapped_column(String, nullable=False)
|
||||
branch_id: Mapped[Identity] = mapped_column(ForeignKey("companies.id"))
|
||||
branch_uu_id: Mapped[UUID] = mapped_column(String, comment="Branch UU ID")
|
||||
|
||||
# company: Mapped["Companies"] = relationship(
|
||||
# "Company", back_populates="company_account_books", foreign_keys=[company_id]
|
||||
@@ -58,24 +60,34 @@ class AccountCodes(CrudCollection):
|
||||
__tablename__ = "account_codes"
|
||||
__exclude__fields__ = []
|
||||
|
||||
account_code = mapped_column(String(48), nullable=False, comment="Account Code")
|
||||
comment_line = mapped_column(String(128), nullable=False, comment="Comment Line")
|
||||
account_code: Mapped[str] = mapped_column(
|
||||
String(48), nullable=False, comment="Account Code"
|
||||
)
|
||||
comment_line: Mapped[str] = mapped_column(
|
||||
String(128), nullable=False, comment="Comment Line"
|
||||
)
|
||||
|
||||
is_receive_or_debit = mapped_column(Boolean)
|
||||
product_id = mapped_column(Integer, server_default="0")
|
||||
nvi_id = mapped_column(String(48), server_default="")
|
||||
status_id = mapped_column(SmallInteger, server_default="0")
|
||||
account_code_seperator = mapped_column(String(1), server_default=".")
|
||||
is_receive_or_debit: Mapped[bool] = mapped_column(Boolean)
|
||||
product_id: Mapped[Identity] = mapped_column(Integer, server_default="0")
|
||||
nvi_id: Mapped[str] = mapped_column(String(48), server_default="")
|
||||
status_id: Mapped[int] = mapped_column(SmallInteger, server_default="0")
|
||||
account_code_seperator: Mapped[str] = mapped_column(String(1), server_default=".")
|
||||
|
||||
system_id = mapped_column(SmallInteger, server_default="0")
|
||||
locked = mapped_column(SmallInteger, server_default="0")
|
||||
system_id: Mapped[int] = mapped_column(SmallInteger, server_default="0")
|
||||
locked: Mapped[bool] = mapped_column(SmallInteger, server_default="0")
|
||||
|
||||
company_id = mapped_column(ForeignKey("companies.id"))
|
||||
company_uu_id = mapped_column(String, nullable=False, comment="Company UU ID")
|
||||
customer_id = mapped_column(ForeignKey("companies.id"))
|
||||
customer_uu_id = mapped_column(String, nullable=False, comment="Customer UU ID")
|
||||
person_id = mapped_column(ForeignKey("people.id"))
|
||||
person_uu_id = mapped_column(String, nullable=False, comment="Person UU ID")
|
||||
company_id: Mapped[Identity] = mapped_column(ForeignKey("companies.id"))
|
||||
company_uu_id: Mapped[UUID] = mapped_column(
|
||||
String, nullable=False, comment="Company UU ID"
|
||||
)
|
||||
customer_id: Mapped[Identity] = mapped_column(ForeignKey("companies.id"))
|
||||
customer_uu_id: Mapped[UUID] = mapped_column(
|
||||
String, nullable=False, comment="Customer UU ID"
|
||||
)
|
||||
person_id: Mapped[Identity] = mapped_column(ForeignKey("people.id"))
|
||||
person_uu_id: Mapped[UUID] = mapped_column(
|
||||
String, nullable=False, comment="Person UU ID"
|
||||
)
|
||||
|
||||
# company: Mapped["Companies"] = relationship(
|
||||
# "Company", back_populates="account_codes", foreign_keys=[company_id]
|
||||
@@ -104,15 +116,17 @@ class AccountCodeParser(CrudCollection):
|
||||
__tablename__ = "account_code_parser"
|
||||
__exclude__fields__ = []
|
||||
|
||||
account_code_1 = mapped_column(String, nullable=False, comment="Order")
|
||||
account_code_2 = mapped_column(String, nullable=False, comment="Order")
|
||||
account_code_3 = mapped_column(String, nullable=False, comment="Order")
|
||||
account_code_4 = mapped_column(String, server_default="")
|
||||
account_code_5 = mapped_column(String, server_default="")
|
||||
account_code_6 = mapped_column(String, server_default="")
|
||||
account_code_1: Mapped[str] = mapped_column(String, nullable=False, comment="Order")
|
||||
account_code_2: Mapped[str] = mapped_column(String, nullable=False, comment="Order")
|
||||
account_code_3: Mapped[str] = mapped_column(String, nullable=False, comment="Order")
|
||||
account_code_4: Mapped[str] = mapped_column(String, server_default="")
|
||||
account_code_5: Mapped[str] = mapped_column(String, server_default="")
|
||||
account_code_6: Mapped[str] = mapped_column(String, server_default="")
|
||||
|
||||
account_code_id = mapped_column(ForeignKey("account_codes.id"), nullable=False)
|
||||
account_code_uu_id = mapped_column(
|
||||
account_code_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("account_codes.id"), nullable=False
|
||||
)
|
||||
account_code_uu_id: Mapped[UUID] = mapped_column(
|
||||
String, nullable=False, comment="Account Code UU ID"
|
||||
)
|
||||
|
||||
@@ -146,51 +160,61 @@ class AccountMaster(CrudCollection):
|
||||
__tablename__ = "account_master"
|
||||
__exclude__fields__ = []
|
||||
|
||||
doc_date = mapped_column(TIMESTAMP, nullable=False, comment="Document Date")
|
||||
plug_type = mapped_column(String, nullable=False, comment="Plug Type")
|
||||
plug_number = mapped_column(Integer, nullable=False, comment="Plug Number")
|
||||
doc_date: Mapped[TIMESTAMP] = mapped_column(
|
||||
TIMESTAMP, nullable=False, comment="Document Date"
|
||||
)
|
||||
plug_type: Mapped[str] = mapped_column(String, nullable=False, comment="Plug Type")
|
||||
plug_number: Mapped[int] = mapped_column(
|
||||
Integer, nullable=False, comment="Plug Number"
|
||||
)
|
||||
|
||||
special_code = mapped_column(String(12), server_default="")
|
||||
authorization_code = mapped_column(String(12), server_default="")
|
||||
special_code: Mapped[str] = mapped_column(String(12), server_default="")
|
||||
authorization_code: Mapped[str] = mapped_column(String(12), server_default="")
|
||||
|
||||
doc_code = mapped_column(String(12), server_default="")
|
||||
doc_type = mapped_column(SmallInteger, server_default="0")
|
||||
doc_code: Mapped[str] = mapped_column(String(12), server_default="")
|
||||
doc_type: Mapped[int] = mapped_column(SmallInteger, server_default="0")
|
||||
|
||||
comment_line1 = mapped_column(String, server_default="")
|
||||
comment_line2 = mapped_column(String, server_default="")
|
||||
comment_line3 = mapped_column(String, server_default="")
|
||||
comment_line4 = mapped_column(String, server_default="")
|
||||
comment_line5 = mapped_column(String, server_default="")
|
||||
comment_line6 = mapped_column(String, server_default="")
|
||||
project_code = mapped_column(String(12), server_default="")
|
||||
module_no = mapped_column(String, server_default="")
|
||||
journal_no = mapped_column(Integer, server_default="0")
|
||||
comment_line1: Mapped[str] = mapped_column(String, server_default="")
|
||||
comment_line2: Mapped[str] = mapped_column(String, server_default="")
|
||||
comment_line3: Mapped[str] = mapped_column(String, server_default="")
|
||||
comment_line4: Mapped[str] = mapped_column(String, server_default="")
|
||||
comment_line5: Mapped[str] = mapped_column(String, server_default="")
|
||||
comment_line6: Mapped[str] = mapped_column(String, server_default="")
|
||||
project_code: Mapped[str] = mapped_column(String(12), server_default="")
|
||||
module_no: Mapped[str] = mapped_column(String, server_default="")
|
||||
journal_no: Mapped[int] = mapped_column(Integer, server_default="0")
|
||||
|
||||
status_id = mapped_column(SmallInteger, server_default="0")
|
||||
canceled = mapped_column(Boolean, server_default="0")
|
||||
print_count = mapped_column(SmallInteger, server_default="0")
|
||||
total_active = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_passive = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_active_1 = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_passive_1 = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_active_2 = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_passive_2 = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_active_3 = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_passive_3 = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_active_4 = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_passive_4 = mapped_column(Numeric(20, 6), server_default="0")
|
||||
cross_ref = mapped_column(Integer, server_default="0")
|
||||
data_center_id = mapped_column(String, server_default="")
|
||||
data_center_rec_num = mapped_column(Integer, server_default="0")
|
||||
status_id: Mapped[int] = mapped_column(SmallInteger, server_default="0")
|
||||
canceled: Mapped[bool] = mapped_column(Boolean, server_default="0")
|
||||
print_count: Mapped[int] = mapped_column(SmallInteger, server_default="0")
|
||||
total_active: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_passive: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_active_1: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_passive_1: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_active_2: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_passive_2: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_active_3: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_passive_3: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_active_4: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
total_passive_4: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
cross_ref: Mapped[int] = mapped_column(Integer, server_default="0")
|
||||
data_center_id: Mapped[str] = mapped_column(String, server_default="")
|
||||
data_center_rec_num: Mapped[int] = mapped_column(Integer, server_default="0")
|
||||
|
||||
account_header_id = mapped_column(ForeignKey("account_books.id"), nullable=False)
|
||||
account_header_uu_id = mapped_column(
|
||||
account_header_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("account_books.id"), nullable=False
|
||||
)
|
||||
account_header_uu_id: Mapped[UUID] = mapped_column(
|
||||
String, nullable=False, comment="Account Header UU ID"
|
||||
)
|
||||
project_item_id = mapped_column(ForeignKey("build_decision_book_projects.id"))
|
||||
project_item_uu_id = mapped_column(String, comment="Project Item UU ID")
|
||||
department_id = mapped_column(ForeignKey("departments.id"))
|
||||
department_uu_id = mapped_column(String, comment="Department UU ID")
|
||||
project_item_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("build_decision_book_projects.id")
|
||||
)
|
||||
project_item_uu_id: Mapped[UUID] = mapped_column(
|
||||
String, comment="Project Item UU ID"
|
||||
)
|
||||
department_id: Mapped[Identity] = mapped_column(ForeignKey("departments.id"))
|
||||
department_uu_id: Mapped[UUID] = mapped_column(String, comment="Department UU ID")
|
||||
|
||||
# account_header: Mapped["AccountBooks"] = relationship(
|
||||
# "AccountBooks",
|
||||
@@ -223,59 +247,77 @@ class AccountDetail(CrudCollection):
|
||||
__exclude__fields__ = []
|
||||
__enum_list__ = [("plug_type", "AccountingReceiptTypes", "M")]
|
||||
|
||||
doc_date = mapped_column(TIMESTAMP, nullable=False, comment="Document Date")
|
||||
line_no = mapped_column(SmallInteger, nullable=False, comment="Line Number")
|
||||
receive_debit = mapped_column(String(1), nullable=False, comment="Receive Debit")
|
||||
debit = mapped_column(Numeric(20, 6), nullable=False, comment="Debit")
|
||||
doc_date: Mapped[TIMESTAMP] = mapped_column(
|
||||
TIMESTAMP, nullable=False, comment="Document Date"
|
||||
)
|
||||
line_no: Mapped[int] = mapped_column(
|
||||
SmallInteger, nullable=False, comment="Line Number"
|
||||
)
|
||||
receive_debit: Mapped[str] = mapped_column(
|
||||
String(1), nullable=False, comment="Receive Debit"
|
||||
)
|
||||
debit: Mapped[float] = mapped_column(
|
||||
Numeric(20, 6), nullable=False, comment="Debit"
|
||||
)
|
||||
|
||||
department = mapped_column(String(24), server_default="")
|
||||
special_code = mapped_column(String(12), server_default="")
|
||||
account_ref = mapped_column(Integer, server_default="0")
|
||||
account_fiche_ref = mapped_column(Integer, server_default="0")
|
||||
center_ref = mapped_column(Integer, server_default="0")
|
||||
general_code = mapped_column(String(32), server_default="")
|
||||
credit = mapped_column(Numeric(20, 6), server_default="0")
|
||||
currency_type = mapped_column(String(4), server_default="TL")
|
||||
exchange_rate = mapped_column(Numeric(20, 6), server_default="0")
|
||||
debit_cur = mapped_column(Numeric(20, 6), server_default="0")
|
||||
credit_cur = mapped_column(Numeric(20, 6), server_default="0")
|
||||
discount_cur = mapped_column(Numeric(20, 6), server_default="0")
|
||||
amount = mapped_column(Numeric(20, 6), server_default="0")
|
||||
cross_account_code = mapped_column(String(32), server_default="")
|
||||
inf_index = mapped_column(Numeric(20, 6), server_default="0")
|
||||
not_inflated = mapped_column(SmallInteger, server_default="0")
|
||||
not_calculated = mapped_column(SmallInteger, server_default="0")
|
||||
comment_line1 = mapped_column(String(64), server_default="")
|
||||
comment_line2 = mapped_column(String(64), server_default="")
|
||||
comment_line3 = mapped_column(String(64), server_default="")
|
||||
comment_line4 = mapped_column(String(64), server_default="")
|
||||
comment_line5 = mapped_column(String(64), server_default="")
|
||||
comment_line6 = mapped_column(String(64), server_default="")
|
||||
owner_acc_ref = mapped_column(Integer, server_default="0")
|
||||
from_where = mapped_column(Integer, server_default="0")
|
||||
orj_eid = mapped_column(Integer, server_default="0")
|
||||
canceled = mapped_column(SmallInteger, server_default="0")
|
||||
cross_ref = mapped_column(Integer, server_default="0")
|
||||
data_center_id = mapped_column(String, server_default="")
|
||||
data_center_rec_num = mapped_column(Integer, server_default="0")
|
||||
status_id = mapped_column(SmallInteger, server_default="0")
|
||||
department: Mapped[str] = mapped_column(String(24), server_default="")
|
||||
special_code: Mapped[str] = mapped_column(String(12), server_default="")
|
||||
account_ref: Mapped[int] = mapped_column(Integer, server_default="0")
|
||||
account_fiche_ref: Mapped[int] = mapped_column(Integer, server_default="0")
|
||||
center_ref: Mapped[int] = mapped_column(Integer, server_default="0")
|
||||
general_code: Mapped[str] = mapped_column(String(32), server_default="")
|
||||
credit: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
currency_type: Mapped[str] = mapped_column(String(4), server_default="TL")
|
||||
exchange_rate: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
debit_cur: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
credit_cur: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
discount_cur: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
amount: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
cross_account_code: Mapped[float] = mapped_column(String(32), server_default="")
|
||||
inf_index: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
not_inflated: Mapped[int] = mapped_column(SmallInteger, server_default="0")
|
||||
not_calculated: Mapped[int] = mapped_column(SmallInteger, server_default="0")
|
||||
comment_line1: Mapped[str] = mapped_column(String(64), server_default="")
|
||||
comment_line2: Mapped[str] = mapped_column(String(64), server_default="")
|
||||
comment_line3: Mapped[str] = mapped_column(String(64), server_default="")
|
||||
comment_line4: Mapped[str] = mapped_column(String(64), server_default="")
|
||||
comment_line5: Mapped[str] = mapped_column(String(64), server_default="")
|
||||
comment_line6: Mapped[str] = mapped_column(String(64), server_default="")
|
||||
owner_acc_ref: Mapped[int] = mapped_column(Integer, server_default="0")
|
||||
from_where: Mapped[int] = mapped_column(Integer, server_default="0")
|
||||
orj_eid: Mapped[int] = mapped_column(Integer, server_default="0")
|
||||
canceled: Mapped[int] = mapped_column(SmallInteger, server_default="0")
|
||||
cross_ref: Mapped[int] = mapped_column(Integer, server_default="0")
|
||||
data_center_id: Mapped[str] = mapped_column(String, server_default="")
|
||||
data_center_rec_num: Mapped[str] = mapped_column(Integer, server_default="0")
|
||||
status_id: Mapped[int] = mapped_column(SmallInteger, server_default="0")
|
||||
|
||||
plug_type_id = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True)
|
||||
plug_type_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("api_enum_dropdown.id"), nullable=True
|
||||
)
|
||||
plug_type_uu_id = mapped_column(String, nullable=False, comment="Plug Type UU ID")
|
||||
account_header_id = mapped_column(ForeignKey("account_books.id"), nullable=False)
|
||||
account_header_uu_id = mapped_column(
|
||||
account_header_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("account_books.id"), nullable=False
|
||||
)
|
||||
account_header_uu_id: Mapped[UUID] = mapped_column(
|
||||
String, nullable=False, comment="Account Header UU ID"
|
||||
)
|
||||
account_code_id = mapped_column(ForeignKey("account_codes.id"), nullable=False)
|
||||
account_code_uu_id = mapped_column(
|
||||
account_code_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("account_codes.id"), nullable=False
|
||||
)
|
||||
account_code_uu_id: Mapped[UUID] = mapped_column(
|
||||
String, nullable=False, comment="Account Code UU ID"
|
||||
)
|
||||
account_master_id = mapped_column(ForeignKey("account_master.id"), nullable=False)
|
||||
account_master_uu_id = mapped_column(
|
||||
account_master_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("account_master.id"), nullable=False
|
||||
)
|
||||
account_master_uu_id: Mapped[UUID] = mapped_column(
|
||||
String, nullable=False, comment="Account Master UU ID"
|
||||
)
|
||||
project_id = mapped_column(ForeignKey("build_decision_book_projects.id"))
|
||||
project_uu_id = mapped_column(String, comment="Project UU ID")
|
||||
project_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("build_decision_book_projects.id")
|
||||
)
|
||||
project_uu_id: Mapped[UUID] = mapped_column(String, comment="Project UU ID")
|
||||
|
||||
# account_header: Mapped["AccountBooks"] = relationship(
|
||||
# "AccountBooks",
|
||||
@@ -342,87 +384,102 @@ class AccountRecords(CrudCollection):
|
||||
build_decision_book_id = kaydın sorumlu olduğu karar defteri
|
||||
send_company_id = kaydı gönderen firma, send_person_id = gönderen kişi
|
||||
customer_id = sorumlu kullanıcı bilgisi, company_id = sorumlu firma
|
||||
|
||||
"""
|
||||
|
||||
iban = mapped_column(String(64), nullable=False, comment="IBAN Number of Bank")
|
||||
bank_date = mapped_column(
|
||||
iban: Mapped[str] = mapped_column(
|
||||
String(64), nullable=False, comment="IBAN Number of Bank"
|
||||
)
|
||||
bank_date: Mapped[TIMESTAMP] = mapped_column(
|
||||
TIMESTAMP, nullable=False, comment="Bank Transaction Date"
|
||||
)
|
||||
|
||||
currency_value = mapped_column(
|
||||
currency_value: Mapped[float] = mapped_column(
|
||||
Numeric(20, 6), nullable=False, comment="Currency Value"
|
||||
)
|
||||
bank_balance = mapped_column(Numeric(20, 6), nullable=False, comment="Bank Balance")
|
||||
currency = mapped_column(String(5), nullable=False, comment="Unit of Currency")
|
||||
additional_balance = mapped_column(
|
||||
bank_balance: Mapped[float] = mapped_column(
|
||||
Numeric(20, 6), nullable=False, comment="Bank Balance"
|
||||
)
|
||||
currency: Mapped[str] = mapped_column(
|
||||
String(5), nullable=False, comment="Unit of Currency"
|
||||
)
|
||||
additional_balance: Mapped[float] = mapped_column(
|
||||
Numeric(20, 6), nullable=False, comment="Additional Balance"
|
||||
)
|
||||
channel_branch = mapped_column(String(120), nullable=False, comment="Branch Bank")
|
||||
process_name = mapped_column(
|
||||
channel_branch: Mapped[str] = mapped_column(
|
||||
String(120), nullable=False, comment="Branch Bank"
|
||||
)
|
||||
process_name: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Bank Process Type Name"
|
||||
)
|
||||
process_type = mapped_column(
|
||||
process_type: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Bank Process Type"
|
||||
)
|
||||
process_comment = mapped_column(
|
||||
process_comment: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Transaction Record Comment"
|
||||
)
|
||||
bank_reference_code = mapped_column(
|
||||
bank_reference_code: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Bank Reference Code"
|
||||
)
|
||||
|
||||
add_comment_note = mapped_column(String, server_default="")
|
||||
is_receipt_mail_send = mapped_column(Boolean, server_default="0")
|
||||
add_comment_note: Mapped[str] = mapped_column(String, server_default="")
|
||||
is_receipt_mail_send: Mapped[bool] = mapped_column(Boolean, server_default="0")
|
||||
found_from = mapped_column(String, server_default="")
|
||||
similarity = mapped_column(Numeric(20, 6), server_default="0")
|
||||
remainder_balance = mapped_column(Numeric(20, 6), server_default="0")
|
||||
similarity: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
remainder_balance: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0")
|
||||
|
||||
bank_date_y = mapped_column(Integer)
|
||||
bank_date_m = mapped_column(SmallInteger)
|
||||
bank_date_w = mapped_column(SmallInteger)
|
||||
bank_date_d = mapped_column(SmallInteger)
|
||||
bank_date_y: Mapped[int] = mapped_column(Integer)
|
||||
bank_date_m: Mapped[int] = mapped_column(SmallInteger)
|
||||
bank_date_w: Mapped[int] = mapped_column(SmallInteger)
|
||||
bank_date_d: Mapped[int] = mapped_column(SmallInteger)
|
||||
|
||||
approving_accounting_record = mapped_column(Boolean, server_default="0")
|
||||
approving_accounting_record: Mapped[bool] = mapped_column(
|
||||
Boolean, server_default="0"
|
||||
)
|
||||
accounting_receipt_date = mapped_column(
|
||||
TIMESTAMP, server_default="1900-01-01 00:00:00"
|
||||
)
|
||||
accounting_receipt_number = mapped_column(Integer, server_default="0")
|
||||
status_id = mapped_column(SmallInteger, server_default="0")
|
||||
|
||||
approved_record = 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")
|
||||
|
||||
receive_debit = mapped_column(ForeignKey("api_enum_dropdown.id"))
|
||||
receive_debit: Mapped[Identity] = mapped_column(ForeignKey("api_enum_dropdown.id"))
|
||||
receive_debit_uu_id = mapped_column(String, nullable=True, comment="Debit UU ID")
|
||||
budget_type = mapped_column(ForeignKey("api_enum_dropdown.uu_id"), nullable=True)
|
||||
budget_type: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("api_enum_dropdown.id"), nullable=True
|
||||
)
|
||||
budget_type_uu_id = mapped_column(
|
||||
String, nullable=True, comment="Budget Type UU ID"
|
||||
)
|
||||
|
||||
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="Company UU ID")
|
||||
send_company_id = mapped_column(ForeignKey("companies.id"))
|
||||
send_company_id: Mapped[Identity] = mapped_column(ForeignKey("companies.id"))
|
||||
send_company_uu_id = mapped_column(
|
||||
String, nullable=True, comment="Send Company UU ID"
|
||||
)
|
||||
|
||||
customer_id = mapped_column(ForeignKey("people.id"))
|
||||
customer_id: Mapped[Identity] = mapped_column(ForeignKey("people.id"))
|
||||
customer_uu_id = mapped_column(String, nullable=True, comment="Customer UU ID")
|
||||
send_person_id = mapped_column(ForeignKey("people.id"))
|
||||
send_person_id: Mapped[Identity] = mapped_column(ForeignKey("people.id"))
|
||||
send_person_uu_id = mapped_column(
|
||||
String, nullable=True, comment="Send Person UU ID"
|
||||
)
|
||||
approving_accounting_person = mapped_column(ForeignKey("people.id"))
|
||||
approving_accounting_person: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("people.id")
|
||||
)
|
||||
approving_accounting_person_uu_id = mapped_column(
|
||||
String, nullable=True, comment="Approving Accounting Person UU ID"
|
||||
)
|
||||
# build_id = mapped_column(ForeignKey("build.id"), nullable=True)
|
||||
build_parts_id = mapped_column(ForeignKey("build_parts.id"))
|
||||
# build_id: Mapped[Identity] = mapped_column(ForeignKey("build.id"), nullable=True)
|
||||
build_parts_id: Mapped[Identity] = mapped_column(ForeignKey("build_parts.id"))
|
||||
build_parts_uu_id = mapped_column(
|
||||
String, nullable=True, comment="Build Parts UU ID"
|
||||
)
|
||||
build_decision_book_id = mapped_column(ForeignKey("build_decision_book.id"))
|
||||
build_decision_book_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("build_decision_book.id")
|
||||
)
|
||||
build_decision_book_uu_id = mapped_column(
|
||||
String, nullable=True, comment="Build Decision Book UU ID"
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from sqlalchemy.orm import mapped_column
|
||||
from sqlalchemy import String, ForeignKey, Index, TIMESTAMP, SmallInteger
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from sqlalchemy import String, ForeignKey, Index, TIMESTAMP, SmallInteger, Identity
|
||||
|
||||
from databases.sql_models.core_mixin import CrudCollection
|
||||
|
||||
@@ -12,21 +12,23 @@ class BuildIbans(CrudCollection):
|
||||
__tablename__ = "build_ibans"
|
||||
__exclude__fields__ = []
|
||||
|
||||
iban = mapped_column(
|
||||
iban: Mapped[str] = mapped_column(
|
||||
String(40), server_default="", nullable=False, comment="IBAN number"
|
||||
)
|
||||
start_date = mapped_column(
|
||||
start_date: Mapped[TIMESTAMP] = mapped_column(
|
||||
TIMESTAMP, nullable=False, comment="Bank Transaction Start Date"
|
||||
)
|
||||
|
||||
stop_date = mapped_column(TIMESTAMP, server_default="2900-01-01 00:00:00")
|
||||
bank_code = mapped_column(String(24), server_default="TR0000000000000")
|
||||
xcomment = mapped_column(String(64), server_default="????")
|
||||
stop_date: Mapped[TIMESTAMP] = mapped_column(
|
||||
TIMESTAMP, server_default="2900-01-01 00:00:00"
|
||||
)
|
||||
bank_code: Mapped[str] = mapped_column(String(24), server_default="TR0000000000000")
|
||||
xcomment: Mapped[str] = mapped_column(String(64), server_default="????")
|
||||
|
||||
build_id = mapped_column(
|
||||
build_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("build.id"), nullable=False, comment="Building ID"
|
||||
)
|
||||
build_uu_id = mapped_column(
|
||||
build_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Building UUID", index=True
|
||||
)
|
||||
# building: Mapped["Build"] = relationship(
|
||||
@@ -57,22 +59,30 @@ class BuildIbanDescription(CrudCollection):
|
||||
__tablename__ = "build_iban_description"
|
||||
__exclude__fields__ = []
|
||||
|
||||
iban = mapped_column(String, nullable=False, comment="IBAN Number")
|
||||
group_id = mapped_column(SmallInteger, nullable=False, comment="Group ID")
|
||||
search_word = mapped_column(
|
||||
iban: Mapped[str] = mapped_column(String, nullable=False, comment="IBAN Number")
|
||||
group_id: Mapped[int] = mapped_column(
|
||||
SmallInteger, nullable=False, comment="Group ID"
|
||||
)
|
||||
search_word: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Search Word", index=True
|
||||
)
|
||||
|
||||
decision_book_project_id = mapped_column(ForeignKey("build_decision_book_projects.id"))
|
||||
decision_book_project_uu_id = mapped_column(
|
||||
decision_book_project_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("build_decision_book_projects.id")
|
||||
)
|
||||
decision_book_project_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Decision Book Project UUID"
|
||||
)
|
||||
customer_id = mapped_column(ForeignKey("people.id"))
|
||||
customer_uu_id = mapped_column(String, nullable=False, comment="Customer UUID")
|
||||
company_id = mapped_column(ForeignKey("companies.id"))
|
||||
company_uu_id = mapped_column(String, nullable=False, comment="Company UUID")
|
||||
build_parts_id = mapped_column(ForeignKey("build_parts.id"))
|
||||
build_parts_uu_id = mapped_column(
|
||||
customer_id: Mapped[Identity] = mapped_column(ForeignKey("people.id"))
|
||||
customer_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Customer UUID"
|
||||
)
|
||||
company_id: Mapped[Identity] = mapped_column(ForeignKey("companies.id"))
|
||||
company_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Company UUID"
|
||||
)
|
||||
build_parts_id: Mapped[Identity] = mapped_column(ForeignKey("build_parts.id"))
|
||||
build_parts_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Build Parts UUID"
|
||||
)
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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")
|
||||
#
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
from fastapi.exceptions import HTTPException
|
||||
|
||||
from databases import (
|
||||
Addresses,
|
||||
Duties,
|
||||
)
|
||||
from databases.sql_models.core_mixin import CrudCollection
|
||||
|
||||
from sqlalchemy import String, Integer, Boolean, ForeignKey, Index
|
||||
from sqlalchemy.orm import mapped_column
|
||||
from sqlalchemy import String, Integer, Boolean, ForeignKey, Index, Identity
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
|
||||
from api_configs import RelationAccess
|
||||
from application.shared_classes import SelectAction, Explanation
|
||||
from validations import InsertCompany, UpdateCompany
|
||||
from validations.company import MatchCompany2Company
|
||||
from valids.auth.token_validations import EmployeeTokenObject
|
||||
from databases.extensions import SelectAction, Explanation
|
||||
from api_validations.validations_request import (
|
||||
InsertCompany,
|
||||
UpdateCompany,
|
||||
MatchCompany2Company,
|
||||
)
|
||||
from api_objects.auth.token_objects import EmployeeTokenObject
|
||||
|
||||
|
||||
class RelationshipDutyCompany(CrudCollection):
|
||||
@@ -28,19 +36,25 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
__exclude__fields__ = []
|
||||
__access_by__ = RelationAccess.SuperAccessList
|
||||
|
||||
owner_id = mapped_column(ForeignKey("companies.id"), nullable=False) # 1
|
||||
duties_id = mapped_column(
|
||||
owner_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("companies.id"), nullable=False
|
||||
) # 1
|
||||
duties_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("duties.id"), nullable=False
|
||||
) # duty -> (n)employee Evyos LTD
|
||||
|
||||
member_id = mapped_column(ForeignKey("companies.id"), nullable=False) # 2, 3, 4
|
||||
parent_id = mapped_column(ForeignKey("companies.id"), nullable=True) # None
|
||||
member_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("companies.id"), nullable=False
|
||||
) # 2, 3, 4
|
||||
parent_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("companies.id"), nullable=True
|
||||
) # None
|
||||
|
||||
relationship_type = mapped_column(
|
||||
relationship_type: Mapped[str] = mapped_column(
|
||||
String, nullable=True, server_default="Commercial"
|
||||
) # Commercial, Organization # Bulk
|
||||
child_count = mapped_column(Integer) # 0
|
||||
show_only = mapped_column(Boolean, server_default="0")
|
||||
child_count: Mapped[int] = mapped_column(Integer) # 0
|
||||
show_only: Mapped[bool] = mapped_column(Boolean, server_default="0")
|
||||
|
||||
# related_company: Mapped[List["Companies"]] = relationship(
|
||||
# "Companies",
|
||||
@@ -50,7 +64,6 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
|
||||
@classmethod
|
||||
def match_company_to_company_commercial(cls, data: MatchCompany2Company, token):
|
||||
from database_sql_models import Companies, Duties
|
||||
|
||||
token_duties_id, token_company_id = token.get("duty_id"), token.get(
|
||||
"company_id"
|
||||
@@ -90,7 +103,6 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
|
||||
@classmethod
|
||||
def match_company_to_company_organization(cls, data: MatchCompany2Company, token):
|
||||
from database_sql_models import Companies, Duties
|
||||
|
||||
token_duties_id, token_company_id = token.get("duty_id"), token.get(
|
||||
"company_id"
|
||||
@@ -119,7 +131,10 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
list_match_company_id.append(bulk_company)
|
||||
|
||||
for match_company_id in list_match_company_id:
|
||||
Duties.init_a_company_default_duties(company_id=match_company_id.id)
|
||||
Duties.init_a_company_default_duties(
|
||||
company_id=match_company_id.id,
|
||||
company_uu_id=str(match_company_id.uu_id),
|
||||
)
|
||||
RelationshipDutyCompany.find_or_create(
|
||||
owner_id=token_company_id,
|
||||
duties_id=send_user_duties.id,
|
||||
@@ -303,23 +318,29 @@ class Companies(CrudCollection, SelectAction):
|
||||
__many__table__ = RelationshipDutyCompany
|
||||
__explain__ = AbstractCompany()
|
||||
|
||||
formal_name = mapped_column(String, nullable=False, comment="Formal Name")
|
||||
company_type = mapped_column(String, nullable=False, comment="Company Type")
|
||||
commercial_type = mapped_column(String, nullable=False, comment="Commercial Type")
|
||||
tax_no = mapped_column(
|
||||
formal_name: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Formal Name"
|
||||
)
|
||||
company_type: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Company Type"
|
||||
)
|
||||
commercial_type: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Commercial Type"
|
||||
)
|
||||
tax_no: Mapped[str] = mapped_column(
|
||||
String, index=True, unique=True, nullable=False, comment="Tax No"
|
||||
)
|
||||
|
||||
public_name = mapped_column(String, comment="Public Name of a company")
|
||||
company_tag = mapped_column(String, comment="Company Tag")
|
||||
default_lang_type = mapped_column(String, server_default="TR")
|
||||
default_money_type = mapped_column(String, server_default="TL")
|
||||
is_commercial = mapped_column(Boolean, server_default="False")
|
||||
is_blacklist = mapped_column(Boolean, server_default="False")
|
||||
public_name: Mapped[str] = mapped_column(String, comment="Public Name of a company")
|
||||
company_tag: Mapped[str] = mapped_column(String, comment="Company Tag")
|
||||
default_lang_type: Mapped[str] = mapped_column(String, server_default="TR")
|
||||
default_money_type: Mapped[str] = mapped_column(String, server_default="TL")
|
||||
is_commercial: Mapped[bool] = mapped_column(Boolean, server_default="False")
|
||||
is_blacklist: Mapped[bool] = mapped_column(Boolean, server_default="False")
|
||||
parent_id = mapped_column(Integer, nullable=True)
|
||||
workplace_no = mapped_column(String, nullable=True)
|
||||
workplace_no: Mapped[str] = mapped_column(String, nullable=True)
|
||||
|
||||
official_address_id = mapped_column(ForeignKey("addresses.id"))
|
||||
official_address_id: Mapped[Identity] = mapped_column(ForeignKey("addresses.id"))
|
||||
official_address_uu_id = mapped_column(
|
||||
String, nullable=True, comment="Official Address UUID"
|
||||
)
|
||||
@@ -347,13 +368,13 @@ class Companies(CrudCollection, SelectAction):
|
||||
from databases import Addresses, Duties
|
||||
|
||||
data_dict = data.model_dump()
|
||||
if cls.filter_one(cls.tax_no==str(data.tax_no).strip()):
|
||||
if cls.filter_one(cls.tax_no == str(data.tax_no).strip()):
|
||||
raise Exception(
|
||||
"Company already exists. Please ask supervisor to make company visible for your duty."
|
||||
)
|
||||
|
||||
official_address = Addresses.filter_one(
|
||||
Addresses.uu_id==data.official_address_uu_id
|
||||
Addresses.uu_id == data.official_address_uu_id
|
||||
)
|
||||
if not official_address:
|
||||
raise HTTPException(
|
||||
@@ -402,8 +423,6 @@ class Companies(CrudCollection, SelectAction):
|
||||
|
||||
@classmethod
|
||||
def update_action(cls, data: UpdateCompany, token):
|
||||
from database_sql_models import Addresses
|
||||
|
||||
data_dict = data.excluded_dump()
|
||||
duty_id = token.get("duty_id")
|
||||
company_id = token.get("company_id")
|
||||
@@ -412,7 +431,7 @@ class Companies(CrudCollection, SelectAction):
|
||||
data_dict["official_address_id"] = official_address.id
|
||||
del data_dict["official_address_uu_id"], data_dict["company_uu_id"]
|
||||
company_to_update = cls.select_action(
|
||||
duty_id=duty_id,
|
||||
duty_id_list=[duty_id],
|
||||
filter_expr=[
|
||||
cls.uu_id == data.company_uu_id,
|
||||
RelationshipDutyCompany.parent_id == company_id,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from sqlalchemy import String, Integer, ForeignKey, Index, Boolean
|
||||
from sqlalchemy.orm import mapped_column
|
||||
from sqlalchemy import String, Integer, ForeignKey, Index, Boolean, Identity
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
|
||||
from databases.sql_models.core_mixin import CrudCollection
|
||||
|
||||
@@ -13,13 +13,17 @@ class Departments(CrudCollection):
|
||||
department_code = mapped_column(
|
||||
String(16), nullable=False, index=True, comment="Department Code"
|
||||
)
|
||||
department_name = mapped_column(
|
||||
department_name: Mapped[str] = mapped_column(
|
||||
String(128), nullable=False, comment="Department Name"
|
||||
)
|
||||
department_description = mapped_column(String, server_default="")
|
||||
department_description: Mapped[str] = mapped_column(String, server_default="")
|
||||
|
||||
company_id = mapped_column(ForeignKey("companies.id"), nullable=False)
|
||||
company_uu_id = mapped_column(String, nullable=False, comment="Company UUID")
|
||||
company_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("companies.id"), nullable=False
|
||||
)
|
||||
company_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Company UUID"
|
||||
)
|
||||
|
||||
# @classmethod
|
||||
# def create_action(cls, data: DepartmentsPydantic, token):
|
||||
@@ -35,9 +39,11 @@ class Duty(CrudCollection):
|
||||
__tablename__ = "duty"
|
||||
__exclude__fields__ = []
|
||||
|
||||
duty_name = mapped_column(String, unique=True, nullable=False, comment="Duty Name")
|
||||
duty_code = mapped_column(String, nullable=False, comment="Duty Code")
|
||||
duty_description = mapped_column(String, comment="Duty Description")
|
||||
duty_name: Mapped[str] = mapped_column(
|
||||
String, unique=True, nullable=False, comment="Duty Name"
|
||||
)
|
||||
duty_code: Mapped[str] = mapped_column(String, nullable=False, comment="Duty Code")
|
||||
duty_description: Mapped[str] = mapped_column(String, comment="Duty Description")
|
||||
|
||||
# @classmethod
|
||||
# def create_action(cls, data: InsertCompanyDuty, token):
|
||||
@@ -60,15 +66,21 @@ class Duties(CrudCollection):
|
||||
users_default_duty = mapped_column(
|
||||
ForeignKey("duty.id"), nullable=True, comment="Default Duty for Users"
|
||||
)
|
||||
company_id = mapped_column(Integer)
|
||||
company_uu_id = mapped_column(String, nullable=False, comment="Company UUID")
|
||||
duties_id = mapped_column(ForeignKey("duty.id"), nullable=False)
|
||||
duties_uu_id = mapped_column(String, nullable=False, comment="Duty UUID")
|
||||
company_id: Mapped[int] = mapped_column(Integer)
|
||||
company_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Company UUID"
|
||||
)
|
||||
duties_id: Mapped[Identity] = mapped_column(ForeignKey("duty.id"), nullable=False)
|
||||
duties_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Duty UUID"
|
||||
)
|
||||
department_id = mapped_column(
|
||||
ForeignKey("departments.id"), nullable=False, comment="Department ID"
|
||||
)
|
||||
department_uu_id = mapped_column(String, nullable=False, comment="Department UUID")
|
||||
# priority_id = mapped_column(ForeignKey("priority.id"), nullable=True)
|
||||
department_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Department UUID"
|
||||
)
|
||||
# priority_id: Mapped[Identity] = mapped_column(ForeignKey("priority.id"), nullable=True)
|
||||
management_duty = mapped_column(
|
||||
Boolean, server_default="0"
|
||||
) # is this a prime Company Duty ???
|
||||
|
||||
@@ -3,11 +3,12 @@ from sqlalchemy import (
|
||||
ForeignKey,
|
||||
Index,
|
||||
Numeric,
|
||||
Identity,
|
||||
)
|
||||
from sqlalchemy.orm import mapped_column
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from databases.sql_models.core_mixin import CrudCollection
|
||||
|
||||
from validations import InsertCompanyEmployees
|
||||
from api_validations.validations_request import InsertCompanyEmployees
|
||||
|
||||
|
||||
class Staff(CrudCollection):
|
||||
@@ -15,14 +16,20 @@ class Staff(CrudCollection):
|
||||
__tablename__ = "staff"
|
||||
__exclude__fields__ = []
|
||||
|
||||
staff_description = mapped_column(
|
||||
staff_description: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Staff Description"
|
||||
)
|
||||
staff_name = mapped_column(String, nullable=False, comment="Staff Name")
|
||||
staff_code = mapped_column(String, nullable=False, comment="Staff Code")
|
||||
staff_name: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Staff Name"
|
||||
)
|
||||
staff_code: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Staff Code"
|
||||
)
|
||||
|
||||
duties_id = mapped_column(ForeignKey("duties.id"), nullable=False)
|
||||
duties_uu_id = mapped_column(String, nullable=False, comment="Duty UUID")
|
||||
duties_id: Mapped[Identity] = mapped_column(ForeignKey("duties.id"), nullable=False)
|
||||
duties_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Duty UUID"
|
||||
)
|
||||
|
||||
# people: Mapped["People"] = relationship(
|
||||
# "People", back_populates="employees", foreign_keys=[people_id], uselist=True
|
||||
@@ -33,7 +40,7 @@ class Staff(CrudCollection):
|
||||
|
||||
@classmethod
|
||||
def create_action(cls, data: InsertCompanyEmployees):
|
||||
from database_sql_models import Duties
|
||||
from databases import Duties
|
||||
|
||||
data_dict = data.model_dump()
|
||||
if duty := Duties.find_one(uu_id=data.duty_uu_id):
|
||||
@@ -56,10 +63,14 @@ class Employees(CrudCollection):
|
||||
__tablename__ = "employees"
|
||||
__exclude__fields__ = []
|
||||
|
||||
staff_id = mapped_column(ForeignKey("staff.id"))
|
||||
staff_uu_id = mapped_column(String, nullable=False, comment="Staff UUID")
|
||||
people_id = mapped_column(ForeignKey("people.id"), nullable=True)
|
||||
people_uu_id = mapped_column(String, nullable=True, comment="People UUID")
|
||||
staff_id: Mapped[Identity] = mapped_column(ForeignKey("staff.id"))
|
||||
staff_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Staff UUID"
|
||||
)
|
||||
people_id: Mapped[Identity] = mapped_column(ForeignKey("people.id"), nullable=True)
|
||||
people_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=True, comment="People UUID"
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
Index("employees_ndx_00", people_id, staff_id, unique=True),
|
||||
@@ -72,12 +83,18 @@ class EmployeeHistory(CrudCollection):
|
||||
__tablename__ = "employee_history"
|
||||
__exclude__fields__ = []
|
||||
|
||||
staff_id = mapped_column(ForeignKey("staff.id"), nullable=False, comment="Staff ID")
|
||||
staff_uu_id = mapped_column(String, nullable=False, comment="Staff UUID")
|
||||
people_id = mapped_column(
|
||||
staff_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("staff.id"), nullable=False, comment="Staff ID"
|
||||
)
|
||||
staff_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Staff UUID"
|
||||
)
|
||||
people_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("people.id"), nullable=False, comment="People ID"
|
||||
)
|
||||
people_uu_id = mapped_column(String, nullable=False, comment="People UUID")
|
||||
people_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="People UUID"
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
Index("_employee_history_ndx_00", people_id, staff_id),
|
||||
@@ -90,11 +107,17 @@ class EmployeesSalaries(CrudCollection):
|
||||
__tablename__ = "employee_salaries"
|
||||
__exclude__fields__ = []
|
||||
|
||||
gross_salary = mapped_column(Numeric(20, 6), nullable=False, comment="Gross Salary")
|
||||
net_salary = mapped_column(Numeric(20, 6), nullable=False, comment="Net Salary")
|
||||
gross_salary: Mapped[float] = mapped_column(
|
||||
Numeric(20, 6), nullable=False, comment="Gross Salary"
|
||||
)
|
||||
net_salary: Mapped[float] = mapped_column(
|
||||
Numeric(20, 6), nullable=False, comment="Net Salary"
|
||||
)
|
||||
|
||||
people_id = mapped_column(ForeignKey("people.id"), nullable=False)
|
||||
people_uu_id = mapped_column(String, nullable=False, comment="People UUID")
|
||||
people_id: Mapped[Identity] = mapped_column(ForeignKey("people.id"), nullable=False)
|
||||
people_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="People UUID"
|
||||
)
|
||||
|
||||
# people: Mapped["People"] = relationship(
|
||||
# "People", back_populates="employee_salaries", foreign_keys=[people_id]
|
||||
|
||||
@@ -67,8 +67,12 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||
creds: Credentials = None # The credentials to use in the model.
|
||||
client_arrow: DateTimeLocal = None # The arrow to use in the model.
|
||||
|
||||
expiry_starts: Mapped[TIMESTAMP] = mapped_column(TIMESTAMP, server_default=func.now(), nullable=False)
|
||||
expiry_ends: Mapped[TIMESTAMP] = mapped_column(TIMESTAMP, default="2099-12-31", server_default="2099-12-31")
|
||||
expiry_starts: Mapped[TIMESTAMP] = mapped_column(
|
||||
TIMESTAMP, server_default=func.now(), nullable=False
|
||||
)
|
||||
expiry_ends: Mapped[TIMESTAMP] = mapped_column(
|
||||
TIMESTAMP, default="2099-12-31", server_default="2099-12-31"
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def extract_system_fields(cls, filter_kwargs: dict, create: bool = True):
|
||||
@@ -76,7 +80,9 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||
Extracts the system fields from the given attributes.
|
||||
"""
|
||||
system_fields = filter_kwargs.copy()
|
||||
extract_fields = cls.__system__fields__create__ if create else cls.__system__fields__update__
|
||||
extract_fields = (
|
||||
cls.__system__fields__create__ if create else cls.__system__fields__update__
|
||||
)
|
||||
for field in extract_fields:
|
||||
system_fields.pop(field, None)
|
||||
return system_fields
|
||||
@@ -84,6 +90,7 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||
@classmethod
|
||||
def find_or_create(cls, **kwargs):
|
||||
from api_library.date_time_actions.date_functions import system_arrow
|
||||
|
||||
"""
|
||||
Finds a record with the given attributes or creates it if it doesn't exist.
|
||||
If found, sets is_found to True, otherwise False.
|
||||
@@ -163,7 +170,9 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||
self.flush()
|
||||
return self
|
||||
|
||||
def get_dict(self, exclude: list = None, include: list = None, include_joins: list = None):
|
||||
def get_dict(
|
||||
self, exclude: list = None, include: list = None, include_joins: list = None
|
||||
):
|
||||
return_dict = {}
|
||||
if exclude:
|
||||
exclude.extend(list(set(self.__exclude__fields__).difference(exclude)))
|
||||
@@ -263,4 +272,4 @@ class CrudCollection(CrudMixin, BaseMixin, SmartQueryMixin):
|
||||
deleted: Mapped[bool] = mapped_column(Boolean, server_default="0")
|
||||
active: Mapped[bool] = mapped_column(Boolean, server_default="1")
|
||||
is_notification_send: Mapped[bool] = mapped_column(Boolean, server_default="0")
|
||||
is_email_send: Mapped[bool] = mapped_column(Boolean, server_default="0")
|
||||
is_email_send: Mapped[bool] = mapped_column(Boolean, server_default="0")
|
||||
|
||||
@@ -8,8 +8,9 @@ from sqlalchemy import (
|
||||
Boolean,
|
||||
Integer,
|
||||
Index,
|
||||
Identity,
|
||||
)
|
||||
from sqlalchemy.orm import mapped_column
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
|
||||
|
||||
class Events(CrudCollection):
|
||||
@@ -21,20 +22,30 @@ class Events(CrudCollection):
|
||||
__tablename__ = "events"
|
||||
__exclude__fields__ = []
|
||||
|
||||
event_type = mapped_column(String, nullable=False, comment="default")
|
||||
function_code = mapped_column(String, nullable=False, comment="function code")
|
||||
function_class = mapped_column(String, nullable=False, comment="class name")
|
||||
event_type: Mapped[str] = mapped_column(String, nullable=False, comment="default")
|
||||
function_code: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="function code"
|
||||
)
|
||||
function_class: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="class name"
|
||||
)
|
||||
|
||||
# name = mapped_column(String, nullable=True) # form or page title
|
||||
description = mapped_column(String, server_default="") # form or page description
|
||||
property_description = mapped_column(String, server_default="")
|
||||
# name: Mapped[str] = mapped_column(String, nullable=True) # form or page title
|
||||
description: Mapped[str] = mapped_column(
|
||||
String, server_default=""
|
||||
) # form or page description
|
||||
property_description: Mapped[str] = mapped_column(String, server_default="")
|
||||
|
||||
marketing_layer = mapped_column(SmallInteger, server_default="3")
|
||||
cost = mapped_column(Numeric(20, 2), server_default="0.00")
|
||||
unit_price = mapped_column(Numeric(20, 2), server_default="0.00")
|
||||
cost: Mapped[float] = mapped_column(Numeric(20, 2), server_default="0.00")
|
||||
unit_price: Mapped[float] = mapped_column(Numeric(20, 2), server_default="0.00")
|
||||
|
||||
endpoint_id = mapped_column(ForeignKey("endpoint_restriction.id"), nullable=True)
|
||||
endpoint_uu_id = mapped_column(String, nullable=True, comment="Endpoint UUID")
|
||||
endpoint_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("endpoint_restriction.id"), nullable=True
|
||||
)
|
||||
endpoint_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=True, comment="Endpoint UUID"
|
||||
)
|
||||
|
||||
__table_args__ = ({"comment": "Events Information"},)
|
||||
|
||||
@@ -47,9 +58,13 @@ class Modules(CrudCollection):
|
||||
__tablename__ = "modules"
|
||||
__exclude__fields__ = []
|
||||
|
||||
module_name = mapped_column(String, nullable=False, comment="Module Name")
|
||||
module_description = mapped_column(String, server_default="")
|
||||
module_code = mapped_column(String, nullable=False, comment="Module Code")
|
||||
module_name: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Module Name"
|
||||
)
|
||||
module_description: Mapped[str] = mapped_column(String, server_default="")
|
||||
module_code: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Module Code"
|
||||
)
|
||||
module_layer = mapped_column(Integer, nullable=False, comment="Module Layer")
|
||||
is_default_module = mapped_column(Boolean, server_default="0")
|
||||
|
||||
@@ -77,12 +92,20 @@ class Services(CrudCollection):
|
||||
__tablename__ = "services"
|
||||
__exclude__fields__ = []
|
||||
|
||||
module_id = mapped_column(ForeignKey("modules.id"), nullable=False)
|
||||
module_uu_id = mapped_column(String, nullable=False, comment="Module UUID")
|
||||
service_name = mapped_column(String, nullable=False, comment="Service Name")
|
||||
service_description = mapped_column(String, server_default="")
|
||||
service_code = mapped_column(String, nullable=True, comment="Service Code")
|
||||
related_responsibility = mapped_column(String, server_default="")
|
||||
module_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("modules.id"), nullable=False
|
||||
)
|
||||
module_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Module UUID"
|
||||
)
|
||||
service_name: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Service Name"
|
||||
)
|
||||
service_description: Mapped[str] = mapped_column(String, server_default="")
|
||||
service_code: Mapped[str] = mapped_column(
|
||||
String, nullable=True, comment="Service Code"
|
||||
)
|
||||
related_responsibility: Mapped[str] = mapped_column(String, server_default="")
|
||||
|
||||
__table_args__ = ({"comment": "Services Information"},)
|
||||
|
||||
@@ -95,9 +118,11 @@ class Service2Events(CrudCollection):
|
||||
__tablename__ = "services2events"
|
||||
__exclude__fields__ = []
|
||||
|
||||
service_id = mapped_column(ForeignKey("services.id"), nullable=False)
|
||||
service_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("services.id"), nullable=False
|
||||
)
|
||||
service_uu_id = mapped_column(String, nullable=False, comment="Service UUID")
|
||||
event_id = mapped_column(ForeignKey("events.id"), nullable=False)
|
||||
event_id: Mapped[Identity] = mapped_column(ForeignKey("events.id"), nullable=False)
|
||||
event_uu_id = mapped_column(String, nullable=False, comment="Event UUID")
|
||||
|
||||
__table_args__ = ({"comment": "Service2Events Information"},)
|
||||
@@ -144,7 +169,7 @@ class Event2Occupant(CrudCollection):
|
||||
build_living_space_uu_id = mapped_column(
|
||||
String, nullable=False, comment="Build Living Space UUID"
|
||||
)
|
||||
event_id = mapped_column(ForeignKey("events.id"), nullable=False)
|
||||
event_id: Mapped[Identity] = mapped_column(ForeignKey("events.id"), nullable=False)
|
||||
event_uu_id = mapped_column(String, nullable=False, comment="Event UUID")
|
||||
|
||||
__table_args__ = (
|
||||
@@ -180,13 +205,19 @@ class ModulePrice(CrudCollection):
|
||||
__exclude__fields__ = []
|
||||
|
||||
campaign_code = mapped_column(String, nullable=False, comment="Campaign Code")
|
||||
module_id = mapped_column(ForeignKey("modules.id"), nullable=False)
|
||||
module_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("modules.id"), nullable=False
|
||||
)
|
||||
module_uu_id = mapped_column(String, nullable=False, comment="Module UUID")
|
||||
service_id = mapped_column(ForeignKey("services.id"), nullable=False)
|
||||
service_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("services.id"), nullable=False
|
||||
)
|
||||
service_uu_id = mapped_column(String, nullable=False, comment="Service UUID")
|
||||
event_id = mapped_column(ForeignKey("events.id"), nullable=False)
|
||||
event_id: Mapped[Identity] = mapped_column(ForeignKey("events.id"), nullable=False)
|
||||
event_uu_id = mapped_column(String, nullable=False, comment="Event UUID")
|
||||
is_counted_percentage = mapped_column(Numeric(6, 2), server_default="0.00") # %22
|
||||
is_counted_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
|
||||
@@ -207,7 +238,7 @@ class ModulePrice(CrudCollection):
|
||||
# __tablename__ = "modules2_occupant"
|
||||
#
|
||||
#
|
||||
# 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
|
||||
@@ -230,7 +261,7 @@ class ModulePrice(CrudCollection):
|
||||
#
|
||||
# __tablename__ = "modules2_employee"
|
||||
#
|
||||
# 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
|
||||
|
||||
@@ -5,7 +5,8 @@ from datetime import timedelta
|
||||
from fastapi import HTTPException
|
||||
|
||||
from databases.sql_models.core_mixin import CrudCollection
|
||||
from application.shared_classes import SelectAction, SelectActionWithEmployee
|
||||
from databases.extensions import SelectAction, SelectActionWithEmployee
|
||||
from databases import Employees, Duties
|
||||
|
||||
from sqlalchemy import (
|
||||
String,
|
||||
@@ -19,11 +20,12 @@ from sqlalchemy import (
|
||||
Integer,
|
||||
Text,
|
||||
or_,
|
||||
Identity,
|
||||
)
|
||||
from sqlalchemy.orm import mapped_column, relationship
|
||||
from sqlalchemy.orm import mapped_column, relationship, Mapped
|
||||
|
||||
from validations import InsertUsers, InsertPerson
|
||||
from extensions.auth.login import UserLoginModule
|
||||
from api_validations.validations_request import InsertUsers, InsertPerson
|
||||
from databases.extensions.auth import UserLoginModule
|
||||
|
||||
|
||||
class UsersTokens(CrudCollection):
|
||||
@@ -31,11 +33,11 @@ class UsersTokens(CrudCollection):
|
||||
__tablename__ = "users_tokens"
|
||||
__exclude__fields__ = []
|
||||
|
||||
user_id = mapped_column(ForeignKey("users.id"), nullable=False)
|
||||
user_id: Mapped[Identity] = mapped_column(ForeignKey("users.id"), nullable=False)
|
||||
|
||||
token_type = mapped_column(String(16), server_default="RememberMe")
|
||||
token = mapped_column(String, server_default="")
|
||||
domain = mapped_column(String, server_default="")
|
||||
token_type: Mapped[str] = mapped_column(String(16), server_default="RememberMe")
|
||||
token: Mapped[str] = mapped_column(String, server_default="")
|
||||
domain: Mapped[str] = mapped_column(String, server_default="")
|
||||
expires_at = mapped_column(TIMESTAMP, default=str(DateTimeLocal.shift(days=3)))
|
||||
|
||||
# users = relationship("Users", back_populates="tokens", foreign_keys=[user_id])
|
||||
@@ -69,14 +71,16 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
|
||||
comment="Email 1/ Phone 2/ User Tag 3 All 111 Only 100",
|
||||
)
|
||||
|
||||
avatar = mapped_column(String, server_default="", comment="Avatar URL for the user")
|
||||
hash_password = mapped_column(
|
||||
avatar: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Avatar URL for the user"
|
||||
)
|
||||
hash_password: Mapped[str] = mapped_column(
|
||||
String(256), server_default="", comment="Hashed password for security"
|
||||
)
|
||||
password_token = mapped_column(
|
||||
password_token: Mapped[str] = mapped_column(
|
||||
String(256), server_default="", comment="Token for password reset"
|
||||
)
|
||||
remember_me = mapped_column(
|
||||
remember_me: Mapped[bool] = mapped_column(
|
||||
Boolean, server_default="0", comment="Flag to remember user login"
|
||||
)
|
||||
|
||||
@@ -92,7 +96,7 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
|
||||
server_default=func.now(),
|
||||
comment="Timestamp when password expiry begins",
|
||||
)
|
||||
related_company = mapped_column(String, comment="Related Company UUID")
|
||||
related_company: Mapped[str] = mapped_column(String, comment="Related Company UUID")
|
||||
|
||||
person_id = mapped_column(
|
||||
ForeignKey("people.id"), nullable=False, comment="Foreign key to person table"
|
||||
@@ -214,8 +218,6 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
|
||||
# }
|
||||
|
||||
def get_employee_and_duty_details(self):
|
||||
from database_sql_models.company.employee import Employees
|
||||
from database_sql_models.company.department import Duties
|
||||
|
||||
found_person = People.find_one(id=self.person_id)
|
||||
found_employees = Employees.filter_by_active(
|
||||
@@ -265,16 +267,20 @@ class RelationshipDutyPeople(CrudCollection):
|
||||
__exclude__fields__ = []
|
||||
__access_by__ = RelationAccess.SuperAccessList
|
||||
|
||||
company_id = mapped_column(ForeignKey("companies.id"), nullable=False) # 1, 2, 3
|
||||
company_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("companies.id"), nullable=False
|
||||
) # 1, 2, 3
|
||||
duties_id = mapped_column(
|
||||
ForeignKey("duties.id"), nullable=False
|
||||
) # duty -> (n)person Evyos LTD
|
||||
member_id = mapped_column(ForeignKey("people.id"), nullable=False) # 2, 3, 4
|
||||
member_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("people.id"), nullable=False
|
||||
) # 2, 3, 4
|
||||
|
||||
relationship_type = mapped_column(
|
||||
String, nullable=True, server_default="Employee"
|
||||
) # Commercial
|
||||
show_only = mapped_column(Boolean, server_default="0")
|
||||
show_only: Mapped[bool] = mapped_column(Boolean, server_default="0")
|
||||
|
||||
# related_company: Mapped[List["Company"]] = relationship(
|
||||
# "Company",
|
||||
@@ -313,43 +319,45 @@ class People(CrudCollection, SelectAction):
|
||||
"tax_no",
|
||||
]
|
||||
|
||||
firstname = mapped_column(
|
||||
firstname: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="First name of the person"
|
||||
)
|
||||
surname = mapped_column(String(24), nullable=False, comment="Surname of the person")
|
||||
middle_name = mapped_column(
|
||||
surname: Mapped[str] = mapped_column(
|
||||
String(24), nullable=False, comment="Surname of the person"
|
||||
)
|
||||
middle_name: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Middle name of the person"
|
||||
)
|
||||
sex_code = mapped_column(
|
||||
sex_code: Mapped[str] = mapped_column(
|
||||
String(1), nullable=False, comment="Sex code of the person (e.g., M/F)"
|
||||
)
|
||||
person_ref = mapped_column(
|
||||
person_ref: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Reference ID for the person"
|
||||
)
|
||||
person_tag = mapped_column(
|
||||
person_tag: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Unique tag for the person"
|
||||
)
|
||||
|
||||
# ENCRYPT DATA
|
||||
father_name = mapped_column(
|
||||
father_name: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Father's name of the person"
|
||||
)
|
||||
mother_name = mapped_column(
|
||||
mother_name: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Mother's name of the person"
|
||||
)
|
||||
country_code = mapped_column(
|
||||
country_code: Mapped[str] = mapped_column(
|
||||
String(4), server_default="TR", comment="Country code of the person"
|
||||
)
|
||||
national_identity_id = mapped_column(
|
||||
national_identity_id: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="National identity ID of the person"
|
||||
)
|
||||
birth_place = mapped_column(
|
||||
birth_place: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Birth place of the person"
|
||||
)
|
||||
birth_date = mapped_column(
|
||||
TIMESTAMP, server_default="1900-01-01", comment="Birth date of the person"
|
||||
)
|
||||
tax_no = mapped_column(
|
||||
tax_no: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Tax number of the person"
|
||||
)
|
||||
# ENCRYPT DATA
|
||||
@@ -366,15 +374,12 @@ class People(CrudCollection, SelectAction):
|
||||
{"comment": "Person Information"},
|
||||
)
|
||||
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
return f"{self.firstname} {self.middle_name} {self.surname}"
|
||||
|
||||
@classmethod
|
||||
def create_action(cls, data: InsertPerson, token):
|
||||
from database_sql_models import Duties
|
||||
|
||||
token_duties_id, token_company_id = (
|
||||
token.selected_company.duty_id,
|
||||
token.selected_company.company_id,
|
||||
@@ -417,14 +422,20 @@ class RelationshipEmployee2PostCode(CrudCollection):
|
||||
__exclude__fields__ = []
|
||||
__include__fields__ = []
|
||||
|
||||
company_id = mapped_column(ForeignKey("companies.id"), nullable=True) # 1, 2, 3
|
||||
employee_id = mapped_column(ForeignKey("employees.id"), nullable=False)
|
||||
member_id = mapped_column(ForeignKey("address_postcode.id"), nullable=False)
|
||||
company_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("companies.id"), nullable=True
|
||||
) # 1, 2, 3
|
||||
employee_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("employees.id"), nullable=False
|
||||
)
|
||||
member_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("address_postcode.id"), nullable=False
|
||||
)
|
||||
|
||||
relationship_type = mapped_column(
|
||||
String, nullable=True, server_default="Employee"
|
||||
) # Commercial
|
||||
show_only = mapped_column(Boolean, server_default="0")
|
||||
show_only: Mapped[bool] = mapped_column(Boolean, server_default="0")
|
||||
|
||||
__table_args__ = ({"comment": "Build2Employee Relationship Information"},)
|
||||
|
||||
@@ -439,7 +450,7 @@ class AddressPostcode(CrudCollection, SelectActionWithEmployee):
|
||||
__access_by__ = []
|
||||
__many__table__ = RelationshipEmployee2PostCode
|
||||
|
||||
street_id = mapped_column(ForeignKey("address_street.id"))
|
||||
street_id: Mapped[Identity] = mapped_column(ForeignKey("address_street.id"))
|
||||
street_uu_id = mapped_column(String, server_default="", comment="Street UUID")
|
||||
postcode = mapped_column(String(32), nullable=False, comment="Postcode")
|
||||
|
||||
@@ -462,10 +473,12 @@ class Addresses(CrudCollection):
|
||||
letter_address = mapped_column(String, nullable=False, comment="Address")
|
||||
short_letter_address = mapped_column(String, nullable=False, comment="Address")
|
||||
|
||||
latitude = mapped_column(Numeric(20, 12), server_default="0")
|
||||
longitude = mapped_column(Numeric(20, 12), server_default="0")
|
||||
latitude: Mapped[float] = mapped_column(Numeric(20, 12), server_default="0")
|
||||
longitude: Mapped[float] = mapped_column(Numeric(20, 12), server_default="0")
|
||||
|
||||
street_id = mapped_column(ForeignKey("address_street.id"), nullable=False)
|
||||
street_id: Mapped[Identity] = mapped_column(
|
||||
ForeignKey("address_street.id"), nullable=False
|
||||
)
|
||||
street_uu_id = mapped_column(String, server_default="", comment="Street UUID")
|
||||
|
||||
@classmethod
|
||||
@@ -612,7 +625,7 @@ class AddressState(CrudCollection):
|
||||
BigInteger, nullable=True, comment="Address Geographic Id"
|
||||
)
|
||||
|
||||
country_id = mapped_column(ForeignKey("address_country.id"))
|
||||
country_id: Mapped[Identity] = mapped_column(ForeignKey("address_country.id"))
|
||||
country_uu_id = mapped_column(String, server_default="", comment="Country UUID")
|
||||
|
||||
__table_args__ = (
|
||||
@@ -643,7 +656,7 @@ class AddressCity(CrudCollection):
|
||||
BigInteger, nullable=True, comment="Address Geographic Id"
|
||||
)
|
||||
|
||||
state_id = mapped_column(ForeignKey("address_state.id"))
|
||||
state_id: Mapped[Identity] = mapped_column(ForeignKey("address_state.id"))
|
||||
state_uu_id = mapped_column(String, server_default="", comment="State UUID")
|
||||
|
||||
__table_args__ = (
|
||||
@@ -702,7 +715,7 @@ class AddressLocality(CrudCollection):
|
||||
type_code = mapped_column(String, nullable=True, comment="Type Name")
|
||||
type_description = mapped_column(String, nullable=True, comment="Type Name")
|
||||
gov_code = mapped_column(String(128), nullable=True, comment="Government Code")
|
||||
address_show = mapped_column(Boolean, server_default="1")
|
||||
address_show: Mapped[bool] = mapped_column(Boolean, server_default="1")
|
||||
address_geographic_id = mapped_column(
|
||||
BigInteger, nullable=True, comment="Address Geographic Id"
|
||||
)
|
||||
@@ -740,7 +753,7 @@ class AddressNeighborhood(CrudCollection):
|
||||
type_code = mapped_column(String, nullable=True, comment="Type Name")
|
||||
type_description = mapped_column(String, nullable=True, comment="Type Name")
|
||||
gov_code = mapped_column(String(128), nullable=True, comment="Government Code")
|
||||
address_show = mapped_column(Boolean, server_default="1")
|
||||
address_show: Mapped[bool] = mapped_column(Boolean, server_default="1")
|
||||
address_geographic_id = mapped_column(
|
||||
BigInteger, nullable=True, comment="Address Geographic Id"
|
||||
)
|
||||
@@ -871,7 +884,7 @@ class OccupantTypes(CrudCollection):
|
||||
occupant_code = mapped_column(String, server_default="")
|
||||
occupant_category = mapped_column(String, server_default="")
|
||||
occupant_category_type = mapped_column(String, server_default="")
|
||||
occupant_is_unique = mapped_column(Boolean, server_default="0")
|
||||
occupant_is_unique: Mapped[bool] = mapped_column(Boolean, server_default="0")
|
||||
|
||||
__table_args__ = ({"comment": "Occupant Types Information"},)
|
||||
|
||||
@@ -891,40 +904,52 @@ class Contracts(CrudCollection):
|
||||
"""
|
||||
Contract class based on declarative_base and BaseMixin via session
|
||||
"""
|
||||
__tablename__ = 'contracts'
|
||||
|
||||
__tablename__ = "contracts"
|
||||
__exclude__fields__ = []
|
||||
|
||||
contract_type = mapped_column(String(5), nullable=False, comment="The code for personnel is P and the code for companies is C.")
|
||||
contract_type = mapped_column(
|
||||
String(5),
|
||||
nullable=False,
|
||||
comment="The code for personnel is P and the code for companies is C.",
|
||||
)
|
||||
contract_title = mapped_column(String(255))
|
||||
contract_details = mapped_column(Text)
|
||||
contract_terms = mapped_column(Text)
|
||||
|
||||
contract_code = mapped_column(
|
||||
String(100), nullable=False, comment="contract_code is the unique code given by the system."
|
||||
String(100),
|
||||
nullable=False,
|
||||
comment="contract_code is the unique code given by the system.",
|
||||
)
|
||||
contract_date = mapped_column(
|
||||
TIMESTAMP, server_default="2099-12-31 23:59:59",
|
||||
TIMESTAMP,
|
||||
server_default="2099-12-31 23:59:59",
|
||||
comment="contract date is the date the contract is made. "
|
||||
"expire start is the start date of the contract, expire en is the end date of the contract."
|
||||
"expire start is the start date of the contract, expire en is the end date of the contract.",
|
||||
)
|
||||
|
||||
company_id = mapped_column(Integer, ForeignKey('companies.id'), nullable=True)
|
||||
company_id = mapped_column(Integer, ForeignKey("companies.id"), nullable=True)
|
||||
company_uu_id = mapped_column(String, server_default="", comment="Company UUID")
|
||||
|
||||
person_id = mapped_column(Integer, ForeignKey('people.id'), nullable=True)
|
||||
person_id = mapped_column(Integer, ForeignKey("people.id"), nullable=True)
|
||||
person_uu_id = mapped_column(String, server_default="", comment="Person UUID")
|
||||
|
||||
@classmethod
|
||||
def retrieve_contact_no(cls):
|
||||
import arrow
|
||||
|
||||
# todo When create record contract_code == below string
|
||||
related_date, counter = arrow.now(), 1
|
||||
return f"{related_date.date().year}{str(cls.contract_type)}{str(counter).zfill(6)}"
|
||||
return (
|
||||
f"{related_date.date().year}{str(cls.contract_type)}{str(counter).zfill(6)}"
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
Index("_contract_ndx_01", contract_code, unique=True),
|
||||
{"comment": "Contract Information"}
|
||||
)
|
||||
Index("_contract_ndx_01", contract_code, unique=True),
|
||||
{"comment": "Contract Information"},
|
||||
)
|
||||
|
||||
|
||||
# def selected_employee_and_duty_details(self, selected_duty_uu_id):
|
||||
# from database_sql_models import (
|
||||
|
||||
@@ -4,6 +4,7 @@ from sqlalchemy import (
|
||||
UUID,
|
||||
String,
|
||||
text,
|
||||
Identity,
|
||||
)
|
||||
from sqlalchemy.orm import (
|
||||
Mapped,
|
||||
@@ -16,14 +17,16 @@ class ApiEnumDropdown(BaseCollection):
|
||||
__tablename__ = "api_enum_dropdown"
|
||||
__exclude__fields__ = ["enum_class"]
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
uu_id: Mapped[str] = mapped_column(
|
||||
id: Mapped[Identity] = mapped_column(primary_key=True)
|
||||
uu_id: Mapped[UUID] = mapped_column(
|
||||
UUID, server_default=text("gen_random_uuid()"), index=True, unique=True
|
||||
)
|
||||
enum_class = mapped_column(String, nullable=False, comment="Enum Constant Name")
|
||||
key = mapped_column(String, nullable=False, comment="Enum Key")
|
||||
value = mapped_column(String, nullable=False, comment="Enum Value")
|
||||
description = mapped_column(String, nullable=True)
|
||||
enum_class: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Enum Constant Name"
|
||||
)
|
||||
key: Mapped[str] = mapped_column(String, nullable=False, comment="Enum Key")
|
||||
value: Mapped[str] = mapped_column(String, nullable=False, comment="Enum Value")
|
||||
description: Mapped[str] = mapped_column(String, nullable=True)
|
||||
|
||||
__table_args__ = ({"comment": "Enum objets that are linked to tables"},)
|
||||
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
|
||||
|
||||
|
||||
class AlchemyResponse:
|
||||
"""
|
||||
alchemy_object = [AlchemyObject].filter_non_deleted() -> AlchemyResponse
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from sqlalchemy import Column, String
|
||||
from sqlalchemy import String
|
||||
from databases.sql_models.core_mixin import CrudCollection
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
|
||||
|
||||
class EndpointRestriction(CrudCollection):
|
||||
@@ -10,18 +11,18 @@ class EndpointRestriction(CrudCollection):
|
||||
__tablename__ = "endpoint_restriction"
|
||||
__exclude__fields__ = []
|
||||
|
||||
endpoint_function = Column(
|
||||
endpoint_function: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Function name of the API endpoint"
|
||||
)
|
||||
endpoint_name = Column(
|
||||
endpoint_name: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Name of the API endpoint"
|
||||
)
|
||||
endpoint_method = Column(
|
||||
endpoint_method: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="HTTP method used by the endpoint"
|
||||
)
|
||||
endpoint_desc = Column(
|
||||
endpoint_desc: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Description of the endpoint"
|
||||
)
|
||||
endpoint_code = Column(
|
||||
endpoint_code: Mapped[str] = mapped_column(
|
||||
String, server_default="", unique=True, comment="Unique code for the endpoint"
|
||||
)
|
||||
|
||||
@@ -32,7 +32,7 @@ class FilterAttributes:
|
||||
status_code="HTTP_304_NOT_MODIFIED",
|
||||
error_case=e.__class__.__name__,
|
||||
data={},
|
||||
message=str(e.__context__).split('\n')[0],
|
||||
message=str(e.__context__).split("\n")[0],
|
||||
)
|
||||
|
||||
def destroy(self):
|
||||
@@ -50,7 +50,7 @@ class FilterAttributes:
|
||||
status_code="HTTP_304_NOT_MODIFIED",
|
||||
error_case=e.__class__.__name__,
|
||||
data={},
|
||||
message=str(e.__context__).split('\n')[0],
|
||||
message=str(e.__context__).split("\n")[0],
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -93,6 +93,7 @@ class FilterAttributes:
|
||||
def get_not_expired_query_arg(cls, *arg, expired=True):
|
||||
"""Add expiry_starts and expiry_ends to the query."""
|
||||
from api_library.date_time_actions.date_functions import system_arrow
|
||||
|
||||
if expired:
|
||||
arg_add = (
|
||||
*arg[0],
|
||||
@@ -103,7 +104,7 @@ class FilterAttributes:
|
||||
return arg[0]
|
||||
|
||||
@classmethod
|
||||
def filter_by_all(cls, **kwargs):
|
||||
def filter_by_all(cls, **kwargs):
|
||||
"""
|
||||
Filters all the records regardless of is_deleted, is_confirmed.
|
||||
"""
|
||||
@@ -151,10 +152,12 @@ class FilterAttributes:
|
||||
|
||||
cls.__session__.rollback()
|
||||
raise HTTPException(
|
||||
status_code=getattr(status, status_code, 'HTTP_404_NOT_FOUND'),
|
||||
detail=dumps({
|
||||
"data": data,
|
||||
"error": error_case,
|
||||
"message": message,
|
||||
})
|
||||
status_code=getattr(status, status_code, "HTTP_404_NOT_FOUND"),
|
||||
detail=dumps(
|
||||
{
|
||||
"data": data,
|
||||
"error": error_case,
|
||||
"message": message,
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user