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