alchemy functions updated
This commit is contained in:
@@ -341,15 +341,16 @@ class Build(CrudCollection, SelectActionWithEmployee):
|
||||
@classmethod
|
||||
def update_action(cls, data: UpdateBuild, build_uu_id: str, token):
|
||||
from databases import Addresses
|
||||
|
||||
data_dict = data.excluded_dump()
|
||||
if data.official_address_uu_id:
|
||||
official_address = Addresses.filter_one(
|
||||
Addresses.uu_id==data.address_uu_id
|
||||
Addresses.uu_id == data.address_uu_id
|
||||
).data
|
||||
data_dict["address_id"] = official_address.id if official_address else None
|
||||
del data_dict["address_uu_id"]
|
||||
if build_to_update := cls.filter_one(
|
||||
cls.uu_id==build_uu_id, cls.person_id==token.id
|
||||
cls.uu_id == build_uu_id, cls.person_id == token.id
|
||||
).data:
|
||||
return build_to_update.update(**data_dict)
|
||||
|
||||
@@ -491,7 +492,7 @@ class BuildParts(CrudCollection):
|
||||
)
|
||||
|
||||
if build_types := BuildTypes.filter_one(
|
||||
BuildTypes.uu_id==data.build_part_type_uu_id
|
||||
BuildTypes.uu_id == data.build_part_type_uu_id
|
||||
).data:
|
||||
part_direction = ApiEnumDropdown.get_by_uuid(
|
||||
uuid=str(data.part_direction_uu_id)
|
||||
|
||||
@@ -406,9 +406,9 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||
**book_dict
|
||||
):
|
||||
decision_book = BuildDecisionBook.filter_one(
|
||||
BuildDecisionBook.id==self.build_decision_book_id,
|
||||
BuildDecisionBook.active==True,
|
||||
BuildDecisionBook.is_confirmed==True
|
||||
BuildDecisionBook.id == self.build_decision_book_id,
|
||||
BuildDecisionBook.active == True,
|
||||
BuildDecisionBook.is_confirmed == True,
|
||||
).data
|
||||
person_occupants.update(
|
||||
expiry_starts=decision_book.expiry_starts,
|
||||
@@ -417,8 +417,7 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||
if build_living_space_id:
|
||||
related_service = Services.filter_by_one(
|
||||
related_responsibility=str(occupant_type.occupant_code),
|
||||
active=True,
|
||||
is_confirmed=True,
|
||||
*Services.valid_record_dict
|
||||
)
|
||||
if not related_service:
|
||||
raise HTTPException(
|
||||
@@ -427,9 +426,9 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||
)
|
||||
|
||||
decision_build = Build.filter_one(
|
||||
Build.id==decision_book.build_id,
|
||||
Build.active==True,
|
||||
Build.is_confirmed==True
|
||||
Build.id == decision_book.build_id,
|
||||
Build.active == True,
|
||||
Build.is_confirmed == True,
|
||||
).data
|
||||
management_room = decision_build.management_room
|
||||
if not management_room:
|
||||
@@ -439,16 +438,14 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||
)
|
||||
|
||||
living_space = BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.id==build_living_space_id,
|
||||
BuildLivingSpace.active==True,
|
||||
BuildLivingSpace.is_confirmed==True
|
||||
BuildLivingSpace.id == build_living_space_id,
|
||||
BuildLivingSpace.active == True,
|
||||
BuildLivingSpace.is_confirmed == True,
|
||||
).data
|
||||
expiry_ends = str(
|
||||
system_arrow.get(decision_book.meeting_date).shift(hours=23)
|
||||
)
|
||||
expiry_starts = str(
|
||||
system_arrow.get(decision_book.meeting_date)
|
||||
)
|
||||
expiry_starts = str(system_arrow.get(decision_book.meeting_date))
|
||||
related_living_space = BuildLivingSpace.find_or_create(
|
||||
build_parts_id=management_room.id,
|
||||
build_parts_uu_id=str(management_room.uu_id),
|
||||
@@ -481,10 +478,10 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||
|
||||
def check_occupant_type(self, occupant_type):
|
||||
book_person_occupant_type = BuildDecisionBookPersonOccupants.filter_one(
|
||||
BuildDecisionBookPersonOccupants.build_decision_book_person_id==self.id,
|
||||
BuildDecisionBookPersonOccupants.occupant_type_id==occupant_type.id,
|
||||
BuildDecisionBookPersonOccupants.active==True,
|
||||
BuildDecisionBookPersonOccupants.is_confirmed==True,
|
||||
BuildDecisionBookPersonOccupants.build_decision_book_person_id == self.id,
|
||||
BuildDecisionBookPersonOccupants.occupant_type_id == occupant_type.id,
|
||||
BuildDecisionBookPersonOccupants.active == True,
|
||||
BuildDecisionBookPersonOccupants.is_confirmed == True,
|
||||
).data
|
||||
if not book_person_occupant_type:
|
||||
raise HTTPException(
|
||||
|
||||
@@ -80,6 +80,8 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
||||
|
||||
creds: Credentials = None # The credentials to use in the model.
|
||||
client_arrow: DateTimeLocal = None # The arrow to use in the model.
|
||||
valid_record_dict: dict = {"active": True, "deleted": False}
|
||||
valid_record_args = lambda class_: [class_.active == True, class_.deleted == False]
|
||||
|
||||
expiry_starts: Mapped[TIMESTAMP] = mapped_column(
|
||||
TIMESTAMP, server_default=func.now(), nullable=False
|
||||
|
||||
@@ -181,12 +181,16 @@ class Event2Occupant(CrudCollection):
|
||||
def get_event_id_by_build_living_space_id(
|
||||
cls, build_living_space_id
|
||||
) -> (list, list):
|
||||
active_events = cls.filter_by_active(
|
||||
build_living_space_id=build_living_space_id
|
||||
)
|
||||
active_events_id = [event.event_id for event in active_events.data]
|
||||
active_events = Events.filter_active(Events.id.in_(active_events_id))
|
||||
active_events_uu_id = [str(event.uu_id) for event in active_events.data]
|
||||
active_events = cls.filter_all(
|
||||
cls.build_living_space_id==build_living_space_id,
|
||||
*cls.valid_record_args(cls)
|
||||
).data
|
||||
active_events_id = [event.event_id for event in active_events]
|
||||
active_events = Events.filter_all(
|
||||
Events.id.in_(active_events_id),
|
||||
*Events.valid_record_args(Events)
|
||||
).data
|
||||
active_events_uu_id = [str(event.uu_id) for event in active_events]
|
||||
return active_events_id, active_events_uu_id
|
||||
|
||||
|
||||
|
||||
@@ -136,8 +136,10 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
|
||||
|
||||
@classmethod
|
||||
def create_action(cls, create_user: InsertUsers):
|
||||
|
||||
found_person = People.find_one(uu_id=create_user.people_uu_id)
|
||||
found_person = People.filter_one(
|
||||
People.uu_id==create_user.people_uu_id,
|
||||
*People.valid_record_args(People),
|
||||
).data
|
||||
if not found_person:
|
||||
raise HTTPException(status_code=400, detail="Person not found.")
|
||||
if (
|
||||
@@ -403,12 +405,11 @@ class People(CrudCollection, SelectAction):
|
||||
create_dict["surname"] = str(create_dict["surname"]).upper()
|
||||
create_dict["birth_place"] = str(create_dict["birth_place"]).upper()
|
||||
created_people = cls.find_or_create(**create_dict)
|
||||
if not created_people.is_found:
|
||||
RelationshipDutyPeople.find_or_create(
|
||||
company_id=token.selected_company.company_id,
|
||||
duties_id=bulk_duty.id,
|
||||
member_id=created_people.id,
|
||||
)
|
||||
RelationshipDutyPeople.find_or_create(
|
||||
company_id=token.selected_company.company_id,
|
||||
duties_id=bulk_duty.id,
|
||||
member_id=created_people.id,
|
||||
)
|
||||
return created_people
|
||||
|
||||
|
||||
@@ -495,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.active == True,
|
||||
).data
|
||||
post_code_id_list = [post_code.member_id for post_code in post_code_list]
|
||||
if not post_code_id_list:
|
||||
|
||||
@@ -39,14 +39,14 @@ class ApiEnumDropdown(BaseCollection):
|
||||
if search := cls.query.filter(
|
||||
cls.enum_class.in_(["DebitTypes"]),
|
||||
cls.uu_id == search_uu_id,
|
||||
cls.active == True,
|
||||
cls.active == True,
|
||||
).first():
|
||||
return search
|
||||
elif search_debit:
|
||||
if search := cls.query.filter(
|
||||
cls.enum_class.in_(["DebitTypes"]),
|
||||
cls.key == search_debit,
|
||||
cls.active == True,
|
||||
cls.active == True,
|
||||
).first():
|
||||
return search
|
||||
return cls.query.filter(
|
||||
@@ -57,7 +57,8 @@ class ApiEnumDropdown(BaseCollection):
|
||||
@classmethod
|
||||
def get_due_types(cls):
|
||||
if due_list := cls.filter_all(
|
||||
cls.enum_class == "BuildDuesTypes", cls.key.in_(["BDT-A", "BDT-D"]),
|
||||
cls.enum_class == "BuildDuesTypes",
|
||||
cls.key.in_(["BDT-A", "BDT-D"]),
|
||||
cls.active == True,
|
||||
).data:
|
||||
return [due.uu_id.__str__() for due in due_list]
|
||||
@@ -72,14 +73,14 @@ class ApiEnumDropdown(BaseCollection):
|
||||
if search := cls.query.filter(
|
||||
cls.enum_class.in_(["BuildDuesTypes"]),
|
||||
cls.uu_id == search_uu_id,
|
||||
cls.active == True,
|
||||
cls.active == True,
|
||||
).first():
|
||||
return search
|
||||
elif search_management:
|
||||
if search := cls.query.filter(
|
||||
cls.enum_class.in_(["BuildDuesTypes"]),
|
||||
cls.key == search_management,
|
||||
cls.active == True,
|
||||
cls.active == True,
|
||||
).first():
|
||||
return search
|
||||
return cls.query.filter(
|
||||
@@ -98,9 +99,13 @@ class ApiEnumDropdown(BaseCollection):
|
||||
|
||||
@classmethod
|
||||
def uuid_of_enum(cls, enum_class: str, key: str):
|
||||
return str(getattr(cls.filter_one(
|
||||
cls.enum_class==enum_class, cls.key==key
|
||||
).data, "uu_id", None))
|
||||
return str(
|
||||
getattr(
|
||||
cls.filter_one(cls.enum_class == enum_class, cls.key == key).data,
|
||||
"uu_id",
|
||||
None,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
ApiEnumDropdown.set_session(ApiEnumDropdown.__session__)
|
||||
|
||||
Reference in New Issue
Block a user