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,
|
||||
|
||||
Reference in New Issue
Block a user