alchemy functions updated
This commit is contained in:
@@ -124,11 +124,14 @@ class BuildDecisionBook(CrudCollection):
|
||||
@classmethod
|
||||
def select_action(cls, duty_id, token=None):
|
||||
|
||||
related_companies = Companies.select_action(duty_id=duty_id)
|
||||
related_companies = Companies.select_action(duty_id_list=[int(duty_id)])
|
||||
related_companies_ids = list(
|
||||
related_.id for related_ in related_companies.all()
|
||||
)
|
||||
related_building = Build.filter_all(Build.company_id.in_(related_companies_ids))
|
||||
related_building = Build.filter_all(
|
||||
Build.company_id.in_(related_companies_ids)
|
||||
*Build.valid_record_args(Build),
|
||||
)
|
||||
related_building_ids = list(related_.id for related_ in related_building.data)
|
||||
return cls.filter_all(cls.build_id.in_(related_building_ids)).query
|
||||
|
||||
@@ -158,11 +161,12 @@ class BuildDecisionBook(CrudCollection):
|
||||
expiry_ends.replace(month=expiry_ends.month + 1, day=1) - timedelta(days=1)
|
||||
)
|
||||
|
||||
if decision_book := BuildDecisionBook.filter_all(
|
||||
if decision_book := BuildDecisionBook.filter_one(
|
||||
BuildDecisionBook.build_id == building.id,
|
||||
BuildDecisionBook.expiry_ends > data_dict["expiry_starts"],
|
||||
BuildDecisionBook.decision_type == data_dict.get("decision_type"),
|
||||
).count: # Decision book is already exist:
|
||||
*BuildDecisionBook.valid_record_args(BuildDecisionBook),
|
||||
).data: # Decision book is already exist:
|
||||
cls.raise_http_exception(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
error_case="RECORDEXITS",
|
||||
@@ -418,7 +422,7 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||
related_service = Services.filter_by_one(
|
||||
related_responsibility=str(occupant_type.occupant_code),
|
||||
*Services.valid_record_dict,
|
||||
)
|
||||
).data
|
||||
if not related_service:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -472,8 +476,9 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||
def get_occupant_types(self):
|
||||
if occupants := BuildDecisionBookPersonOccupants.filter_all(
|
||||
BuildDecisionBookPersonOccupants.build_decision_book_person_id == self.id,
|
||||
):
|
||||
return occupants.data
|
||||
*BuildDecisionBookPersonOccupants.valid_record_args(BuildDecisionBookPersonOccupants)
|
||||
).data:
|
||||
return occupants
|
||||
return
|
||||
|
||||
def check_occupant_type(self, occupant_type):
|
||||
@@ -1028,29 +1033,35 @@ class BuildDecisionBookProjects(CrudCollection):
|
||||
@classmethod
|
||||
def select_action(cls, duty_id, token=None):
|
||||
|
||||
related_companies = Companies.select_action(duty_id=duty_id)
|
||||
related_companies = Companies.select_action(duty_id_list=[duty_id])
|
||||
related_companies_ids = list(
|
||||
related_.id for related_ in related_companies.all()
|
||||
)
|
||||
related_building = Build.filter_all(Build.company_id.in_(related_companies_ids))
|
||||
related_building = Build.filter_all(
|
||||
Build.company_id.in_(related_companies_ids),
|
||||
*Build.valid_record_args(Build)
|
||||
)
|
||||
related_building_ids = list(related_.id for related_ in related_building.data)
|
||||
related_decision_books = BuildDecisionBook.query.filter(
|
||||
BuildDecisionBook.build_id.in_(related_building_ids)
|
||||
)
|
||||
related_decision_books = BuildDecisionBook.filter_all(
|
||||
BuildDecisionBook.build_id.in_(related_building_ids),
|
||||
*BuildDecisionBook.valid_record_args(BuildDecisionBook)
|
||||
).data
|
||||
related_decision_books_ids = list(
|
||||
related_.id for related_ in related_decision_books.all()
|
||||
related_.id for related_ in related_decision_books
|
||||
)
|
||||
related_decision_books_items = BuildDecisionBookItems.query.filter(
|
||||
related_decision_books_items = BuildDecisionBookItems.filter_all(
|
||||
BuildDecisionBookItems.build_decision_book_id.in_(
|
||||
related_decision_books_ids
|
||||
)
|
||||
)
|
||||
),
|
||||
*BuildDecisionBookItems.valid_record_args(BuildDecisionBookItems)
|
||||
).data
|
||||
related_decision_books_items_ids = list(
|
||||
related_.id for related_ in related_decision_books_items.all()
|
||||
)
|
||||
return cls.query.filter(
|
||||
cls.build_decision_book_item_id.in_(related_decision_books_items_ids)
|
||||
related_.id for related_ in related_decision_books_items
|
||||
)
|
||||
return cls.filter_all(
|
||||
cls.build_decision_book_item_id.in_(related_decision_books_items_ids),
|
||||
*cls.valid_record_args(cls)
|
||||
).query
|
||||
|
||||
@classmethod
|
||||
def create_action(cls, data: InsertBuildDecisionBookProjects, token=None):
|
||||
|
||||
@@ -175,9 +175,9 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||
"""
|
||||
check_kwargs = cls.extract_system_fields(kwargs)
|
||||
cls.pre_query = cls.query.filter(cls.expiry_ends < system_arrow.now().date())
|
||||
already_record = cls.filter_by_one(**check_kwargs, system=True)
|
||||
already_record = cls.filter_by_one(**check_kwargs, system=True).data
|
||||
cls.pre_query = None
|
||||
if already_record := already_record.data:
|
||||
if already_record:
|
||||
if already_record.deleted:
|
||||
cls.raise_http_exception(
|
||||
status_code="HTTP_406_NOT_ACCEPTABLE",
|
||||
|
||||
@@ -68,8 +68,11 @@ class Modules(CrudCollection):
|
||||
is_default_module = mapped_column(Boolean, server_default="0")
|
||||
|
||||
def retrieve_services(self):
|
||||
services = Services.filter_all(Services.module_id == self.id)
|
||||
if not services.count:
|
||||
services = Services.filter_all(
|
||||
Services.module_id == self.id,
|
||||
*Services.valid_record_args(Services)
|
||||
).data
|
||||
if not services:
|
||||
self.raise_http_exception(
|
||||
status_code="HTTP_404_NOT_FOUND",
|
||||
error_case="RECORD_NOT_FOUND",
|
||||
@@ -78,7 +81,7 @@ class Modules(CrudCollection):
|
||||
"module_uu_id": str(self.uu_id),
|
||||
},
|
||||
)
|
||||
return services.data
|
||||
return services
|
||||
|
||||
__table_args__ = ({"comment": "Modules Information"},)
|
||||
|
||||
@@ -143,9 +146,14 @@ class Event2Employee(CrudCollection):
|
||||
|
||||
@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 = cls.filter_all(
|
||||
cls.employee_id == employee_id, *cls.valid_record_args(cls)
|
||||
)
|
||||
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 = Events.filter_all(
|
||||
Events.id.in_(active_events_id),
|
||||
*Events.valid_record_args(Events)
|
||||
)
|
||||
active_events_uu_id = [str(event.uu_id) for event in active_events.data]
|
||||
return active_events_id, active_events_uu_id
|
||||
|
||||
|
||||
@@ -496,7 +496,7 @@ class Addresses(CrudCollection):
|
||||
post_code_list = RelationshipEmployee2PostCode.filter_all(
|
||||
RelationshipEmployee2PostCode.employee_id
|
||||
== token_dict.selected_company.employee_id,
|
||||
RelationshipEmployee2PostCode.active == True,
|
||||
*RelationshipEmployee2PostCode.valid_record_args(RelationshipEmployee2PostCode)
|
||||
).data
|
||||
post_code_id_list = [post_code.member_id for post_code in post_code_list]
|
||||
if not post_code_id_list:
|
||||
@@ -504,10 +504,12 @@ class Addresses(CrudCollection):
|
||||
status_code=404,
|
||||
detail="User has no post code registered. User can not list addresses.",
|
||||
)
|
||||
cls.pre_query = cls.filter_active(cls.post_code_id.in_(post_code_id_list)).query
|
||||
cls.pre_query = cls.filter_all(
|
||||
cls.post_code_id.in_(post_code_id_list), cls.valid_record_args(cls)
|
||||
).query
|
||||
filter_cls = cls.filter_all(*filter_expr)
|
||||
cls.pre_query = None
|
||||
return filter_cls
|
||||
return filter_cls.data
|
||||
|
||||
# buildings: Mapped["Build"] = relationship(
|
||||
# "Build", back_populates="addresses", foreign_keys="Build.address_id"
|
||||
|
||||
Reference in New Issue
Block a user