alcehmy and event functions updated
This commit is contained in:
@@ -62,9 +62,9 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
detail="Employee cannot create decision book invitations",
|
||||
)
|
||||
# Check token posses the occupant type of Build Manager
|
||||
occupant_manager = OccupantTypes.find_one(
|
||||
occupant_manager = OccupantTypes.filter_by_one(
|
||||
occupant_category_type="BU", occupant_code="BU-MNG"
|
||||
)
|
||||
).get(1)
|
||||
if not token_dict.selected_occupant.occupant_type_id == occupant_manager.id:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
@@ -72,21 +72,24 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
)
|
||||
|
||||
# Check decision book is valid for this token and building
|
||||
decision_book = BuildDecisionBook.find_one(
|
||||
uu_id=data.build_decision_book_uu_id,
|
||||
build_id=token_dict.selected_occupant.build_id,
|
||||
)
|
||||
decision_book = BuildDecisionBook.filter_one(
|
||||
BuildDecisionBook.uu_id==data.build_decision_book_uu_id,
|
||||
BuildDecisionBook.build_id==token_dict.selected_occupant.build_id,
|
||||
BuildDecisionBook.active==True,
|
||||
).get(1)
|
||||
if not decision_book:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Decision book not found. Please create decision book first",
|
||||
)
|
||||
occupant_building = Build.find_one(id=token_dict.selected_occupant.build_id)
|
||||
occupant_building = Build.filter_one(
|
||||
Build.id==token_dict.selected_occupant.build_id
|
||||
).get(1)
|
||||
|
||||
# Check meeting type is valid
|
||||
meeting_type = ApiEnumDropdown.find_one(
|
||||
meeting_type = ApiEnumDropdown.filter_by_one(
|
||||
enum_class="MeetingTypes",
|
||||
)
|
||||
).get(1)
|
||||
if not meeting_type:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
@@ -104,6 +107,9 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
)
|
||||
|
||||
# Create an invitation for specific invitation type to start invite sending process
|
||||
planned_date_expires = str(
|
||||
system_arrow.get(data.planned_date).shift(days=15).date()
|
||||
),
|
||||
book_invitation = BuildDecisionBookInvitations.find_or_create(
|
||||
build_id=token_dict.selected_occupant.build_id,
|
||||
build_uu_id=token_dict.selected_occupant.build_uuid,
|
||||
@@ -114,9 +120,7 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
living_part_percentage=0.51,
|
||||
message=data.message,
|
||||
planned_date=data.planned_date,
|
||||
planned_date_expires=str(
|
||||
system_arrow.get(data.planned_date).shift(days=15).date()
|
||||
),
|
||||
planned_date_expires=planned_date_expires,
|
||||
expiry_ends=str(system_arrow.get(data.planned_date).shift(days=15).date()),
|
||||
is_confirmed=True,
|
||||
)
|
||||
@@ -131,25 +135,22 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
)
|
||||
|
||||
# Get all the parts of the building that is occupant in token
|
||||
build_parts = BuildParts.filter_active(
|
||||
BuildParts.build_id == occupant_building.id
|
||||
)
|
||||
build_parts = BuildParts.filter_all(
|
||||
BuildParts.build_id == occupant_building.id,
|
||||
BuildParts.active == True
|
||||
).data
|
||||
|
||||
# Get all build living spaces that is found in building with distinct person id
|
||||
occupants = OccupantTypes.filter_all()
|
||||
build_living_spaces_people = (
|
||||
BuildLivingSpace.filter_active(
|
||||
BuildLivingSpace.build_parts_id.in_(
|
||||
[build_part.id for build_part in build_parts.data]
|
||||
),
|
||||
BuildLivingSpace.occupant_type.in_(
|
||||
[occupant.id for occupant in occupants.data]
|
||||
),
|
||||
filter_records=False,
|
||||
)
|
||||
.query.distinct(BuildLivingSpace.person_id)
|
||||
.all()
|
||||
)
|
||||
occupants = OccupantTypes.filter_all(system=True)
|
||||
BuildLivingSpace.filter_attr = None
|
||||
build_living_spaces_people = BuildLivingSpace.filter_all(
|
||||
BuildLivingSpace.build_parts_id.in_(
|
||||
[build_part.id for build_part in build_parts.data]
|
||||
),
|
||||
BuildLivingSpace.occupant_type.in_(
|
||||
[occupant.id for occupant in occupants.data]
|
||||
),
|
||||
).query.distinct(BuildLivingSpace.person_id).all()
|
||||
if not build_living_spaces_people:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
@@ -199,21 +200,22 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
invitations_person.add_occupant_type(occupant_type=attendance_occupant_type)
|
||||
if invitations_person and not invitations_person.is_found:
|
||||
print(f'"{invitations_person.token}",')
|
||||
spaces_user = Users.find_one(
|
||||
active=True,
|
||||
is_confirmed=True,
|
||||
person_id=build_living_spaces_user.person_id,
|
||||
)
|
||||
spaces_user = Users.filter_one(
|
||||
Users.active==True,
|
||||
Users.is_confirmed==True,
|
||||
Users.person_id==build_living_spaces_user.person_id,
|
||||
).data
|
||||
# print(
|
||||
# f"Invitation is send : {spaces_user.email} "
|
||||
# f"Token : {invitations_person.token} "
|
||||
# f"Send Date : {str(invitations_person.send_date.date())}"
|
||||
# )
|
||||
|
||||
manager_living_spaces = BuildLivingSpace.filter_active(
|
||||
manager_living_spaces = BuildLivingSpace.filter_all(
|
||||
BuildLivingSpace.person_id == token_dict.person_id,
|
||||
)
|
||||
manager_people = BuildDecisionBookPerson.filter_active(
|
||||
BuildLivingSpace.active == True,
|
||||
).data
|
||||
manager_people = BuildDecisionBookPerson.filter_all(
|
||||
BuildDecisionBookPerson.invite_id == book_invitation.id,
|
||||
BuildDecisionBookPerson.build_living_space_id.in_(
|
||||
[
|
||||
@@ -221,16 +223,15 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
for manager_living_space in manager_living_spaces.data
|
||||
]
|
||||
),
|
||||
BuildLivingSpace.active == True,
|
||||
)
|
||||
manager_people_occupants = BuildDecisionBookPersonOccupants.filter_active(
|
||||
manager_people_occupants = BuildDecisionBookPersonOccupants.filter_all(
|
||||
BuildDecisionBookPersonOccupants.build_decision_book_person_id
|
||||
== manager_people.get(1).id
|
||||
== manager_people.get(1).id,
|
||||
BuildDecisionBookPersonOccupants.active == True,
|
||||
)
|
||||
dlt = [
|
||||
occupants.delete(destroy=True)
|
||||
for occupants in manager_people_occupants.data
|
||||
]
|
||||
dlt = [occupants.delete(destroy=True) for occupants in manager_people.data]
|
||||
manager_people_occupants.query.delete()
|
||||
manager_people.query.delete()
|
||||
|
||||
if book_person_manager := BuildDecisionBookPerson.find_or_create(
|
||||
**build_decision_book_person_dict,
|
||||
|
||||
Reference in New Issue
Block a user