super_user and services updated

This commit is contained in:
2024-12-05 18:59:46 +03:00
parent 88f94c37c2
commit 88309eb49d
20 changed files with 317 additions and 116 deletions

View File

@@ -21,7 +21,9 @@ class Events(CrudCollection):
__tablename__ = "events"
__exclude__fields__ = []
event_type: Mapped[str] = mapped_column(String, nullable=False, comment="Event Type")
event_type: Mapped[str] = mapped_column(
String, nullable=False, comment="Event Type"
)
function_code: Mapped[str] = mapped_column(
String, nullable=False, comment="function code"
)
@@ -123,6 +125,62 @@ class Service2Events(CrudCollection):
__table_args__ = ({"comment": "Service2Events Information"},)
class Event2OccupantExtra(CrudCollection):
__tablename__ = "event2occupant_extra"
__exclude__fields__ = []
build_living_space_id: Mapped[int] = mapped_column(
ForeignKey("build_living_space.id"), nullable=False
)
build_living_space_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Build Living Space UUID"
)
event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), nullable=False)
event_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Event UUID"
)
__table_args__ = (
Index(
"event2occupant_extra_bind_event_to_occupant",
build_living_space_id,
event_id,
unique=True,
),
{"comment": "Occupant2Event Information"},
)
class Event2EmployeeExtra(CrudCollection):
"""
Employee2Event class based on declarative_base and BaseMixin via session
"""
__tablename__ = "event2employee_extra"
__exclude__fields__ = []
employee_id: Mapped[int] = mapped_column(ForeignKey("employees.id"), nullable=False)
employee_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Employee UUID"
)
event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), nullable=False)
event_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Event UUID"
)
__table_args__ = (
Index(
"event2employee_extra_employee_to_event",
employee_id,
event_id,
unique=True,
),
{"comment": "Employee to Event Information"},
)
class Event2Employee(CrudCollection):
"""
Employee2Event class based on declarative_base and BaseMixin via session
@@ -131,23 +189,41 @@ class Event2Employee(CrudCollection):
__tablename__ = "event2employee"
__exclude__fields__ = []
employee_id = mapped_column(ForeignKey("employees.id"), nullable=False)
employee_uu_id = mapped_column(String, nullable=False, comment="Employee UUID")
event_id = mapped_column(ForeignKey("events.id"), nullable=False)
event_uu_id = mapped_column(String, nullable=False, comment="Event UUID")
employee_id: Mapped[int] = mapped_column(ForeignKey("employees.id"), nullable=False)
employee_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Employee UUID"
)
event_service_id: Mapped[int] = mapped_column(
ForeignKey("services.id"), nullable=False
)
event_service_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Event Cluster UUID"
)
__table_args__ = (
Index("event2employee_employee_to_event", employee_id, event_id, unique=True),
Index(
"event2employee_employee_to_event",
employee_id,
event_service_id,
unique=True,
),
{"comment": "Employee to Event Information"},
)
@classmethod
def get_event_id_by_employee_id(cls, employee_id) -> (list, list):
active_events = cls.filter_all(cls.employee_id == employee_id)
active_events_id = [event.event_id for event in active_events.data]
active_events = Events.filter_all(Events.id.in_(active_events_id))
active_events_uu_id = [str(event.uu_id) for event in active_events.data]
return active_events_id, active_events_uu_id
def get_event_id_by_employee_id(cls, employee_id) -> list:
occupant_events = cls.filter_all(
cls.employee_id == employee_id,
).data
active_events = Service2Events.filter_all(
Service2Events.service_id.in_([event.event_service_id for event in occupant_events]), system=True
).data
active_events_id = [event.event_id for event in active_events]
if extra_events := Event2EmployeeExtra.filter_all(
Event2EmployeeExtra.employee_id == employee_id
).data:
active_events_id.extend([event.event_id for event in extra_events])
return active_events_id
class Event2Occupant(CrudCollection):
@@ -158,39 +234,47 @@ class Event2Occupant(CrudCollection):
__tablename__ = "event2occupant"
__exclude__fields__ = []
build_living_space_id = mapped_column(
build_living_space_id: Mapped[str] = mapped_column(
ForeignKey("build_living_space.id"), nullable=False
)
build_living_space_uu_id = mapped_column(
build_living_space_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Build Living Space UUID"
)
event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), nullable=False)
event_uu_id = mapped_column(String, nullable=False, comment="Event UUID")
event_service_id: Mapped[int] = mapped_column(
ForeignKey("services.id"), nullable=False
)
event_service_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Event Cluster UUID"
)
# event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), nullable=False)
# event_uu_id = mapped_column(String, nullable=False, comment="Event UUID")
__table_args__ = (
Index(
"event2occupant_bind_event_to_occupant",
build_living_space_id,
event_id,
event_service_id,
unique=True,
),
{"comment": "Occupant2Event Information"},
)
@classmethod
def get_event_id_by_build_living_space_id(
cls, build_living_space_id
) -> (list, list):
active_events = cls.filter_all(
def get_event_id_by_build_living_space_id(cls, build_living_space_id) -> list:
occupant_events = cls.filter_all(
cls.build_living_space_id == build_living_space_id,
).data
active_events = Service2Events.filter_all(
Service2Events.service_id.in_([event.event_service_id for event in occupant_events]), system=True
).data
active_events_id = [event.event_id for event in active_events]
active_events = Events.filter_all(Events.id.in_(active_events_id)).data
active_events_uu_id = [str(event.uu_id) for event in active_events]
return active_events_id, active_events_uu_id
if extra_events := Event2OccupantExtra.filter_all(
Event2OccupantExtra.build_living_space_id == build_living_space_id
).data:
active_events_id.extend([event.event_id for event in extra_events])
return active_events_id
# Delete later code
class ModulePrice(CrudCollection):
"""
ModulePrice class based on declarative_base and BaseMixin via session
@@ -199,27 +283,34 @@ class ModulePrice(CrudCollection):
__tablename__ = "module_price"
__exclude__fields__ = []
campaign_code = mapped_column(String, nullable=False, comment="Campaign Code")
campaign_code: Mapped[str] = mapped_column(
String, nullable=False, comment="Campaign Code"
)
module_id: Mapped[int] = mapped_column(ForeignKey("modules.id"), nullable=False)
module_uu_id = mapped_column(String, nullable=False, comment="Module UUID")
module_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Module UUID"
)
service_id: Mapped[int] = mapped_column(ForeignKey("services.id"), nullable=False)
service_uu_id = mapped_column(String, nullable=False, comment="Service UUID")
service_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Service UUID"
)
event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), nullable=False)
event_uu_id = mapped_column(String, nullable=False, comment="Event UUID")
event_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Event UUID"
)
is_counted_percentage: Mapped[float] = mapped_column(
Numeric(6, 2), server_default="0.00"
) # %22
discounted_price = mapped_column(
discounted_price: Mapped[float] = mapped_column(
Numeric(20, 2), server_default="0.00"
) # Normal: 78.00 TL
calculated_price = mapped_column(
calculated_price: Mapped[float] = mapped_column(
Numeric(20, 2), server_default="0.00"
) # sana düz 75.00 TL yapar
__table_args__ = ({"comment": "ModulePrice Information"},)
#
# class Modules2Occupant(CrudCollection):
# """
# ModulesOccupantPrices class based on declarative_base and BaseMixin via session