services are checked
This commit is contained in:
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user