Skip to content

Commit

Permalink
Generate Financial Reporting - Bug Fixes (#269)
Browse files Browse the repository at this point in the history
Client reported that financial reporting flag wasn't working properly. This has been fixed and tested to ensure that it's working as intended.

Client asked that there be an option added for ALL BOOKING EVENTS to the generate modal, and that there be an ALL EXAMS option as well. Not merging both options. This has been remedied and the UI to the modal has been updated to have a dropdown with filter options in the dropdown.

Client reported that the ITA and Non-ITA filters were reporting appointments and not just exams. This has been fixed and tested.

During testing, an issue was found with creating rooms in the admin panel. This was fixed being utilizing the `is_created` param in the on_model_change function to check whether or not changes are happening during an EDIT or a CREATE.
  • Loading branch information
sjrumsby authored and gil0109 committed May 24, 2019
1 parent 9ad6e9c commit dd331a5
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 78 deletions.
25 changes: 13 additions & 12 deletions api/app/admin/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,23 @@ def get_query(self):

def on_model_change(self, form, model, is_created):

room_id = get_mdict_item_or_list(request.args, 'id')
today = datetime.now()
today_aware = pytz.utc.localize(today)
if not is_created:
room_id = get_mdict_item_or_list(request.args, 'id')
today = datetime.now()
today_aware = pytz.utc.localize(today)

booking_room = Booking.query.filter_by(room_id=room_id)\
.filter(Booking.start_time > today_aware).count()
booking_room = Booking.query.filter_by(room_id=room_id)\
.filter(Booking.start_time > today_aware).count()

specific_room = Room.query.filter_by(room_id=room_id).first()
room_name = specific_room.room_name
specific_room = Room.query.filter_by(room_id=room_id).first()
room_name = specific_room.room_name

if model.deleted is not None and booking_room > 0:
message = "'" + room_name + "' is currently being used for bookings. " \
if model.deleted is not None and booking_room > 0:
message = "'" + room_name + "' is currently being used for bookings. " \
"Reschedule bookings that use this room before setting the deleted date."
flash(gettext(message), 'warning')
model.deleted = None
form.deleted.data = None
flash(gettext(message), 'warning')
model.deleted = None
form.deleted.data = None

create_modal = False
edit_modal = False
Expand Down
116 changes: 59 additions & 57 deletions api/app/resources/bookings/exam/exam_export_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,18 @@ def get(self):
.join(Office, Booking.office_id == Office.office_id) \
.join(ExamType, Exam.exam_type_id == ExamType.exam_type_id)

non_exams = Booking.query.join(Exam, Booking.booking_id == Exam.booking_id, isouter=True) \
.filter(Booking.start_time >= start_date) \
.filter(Booking.start_time < end_date) \
.filter(Exam.booking_id.is_(None)) \
.join(Room, Booking.room_id == Room.room_id, isouter=True) \
.join(Office, Booking.office_id == Office.office_id) \
if exam_type == 'all_bookings':
non_exams = Booking.query.join(Exam, Booking.booking_id == Exam.booking_id, isouter=True) \
.filter(Booking.start_time >= start_date) \
.filter(Booking.start_time < end_date) \
.filter(Exam.booking_id.is_(None)) \
.join(Room, Booking.room_id == Room.room_id, isouter=True) \
.join(Office, Booking.office_id == Office.office_id) \

if not is_designate:
exams = exams.filter(Booking.office_id == csr.office_id)
if exam_type == 'all_bookings':
non_exams = non_exams.filter(Booking.office_id == csr.office_id)

if exam_type == 'ita':
exams = exams.filter(ExamType.ita_ind == 1)
Expand Down Expand Up @@ -169,51 +172,52 @@ def get(self):
return {"message": "Issue writing row to CSV ",
"key": key}, 500

for non_exam in non_exams:
row = []
try:
for key in keys:
if key == "room_name":
write_booking_room(row, non_exam)
elif key == "invigilator_name":
row.append("")
elif key == "sbc_staff_invigilated":
row.append("")
elif key == "exam_received_date":
row.append("")
elif key == "exam_written_ind":
row.append("")
elif key == "exam_returned_date":
row.append("")
elif key == "office_name":
row.append(getattr(non_exam.office, key))
elif key == "exam_type_name":
row.append("Non Exam Booking")
elif key in booking_keys:
row.append(getattr(non_exam, key))
elif key in non_exam_keys:
which_non_exam_key(non_exam, row, key)
elif key == "exam_id":
row.append("")
elif key == "exam_name":
row.append("")
elif key == "examinee_name":
row.append("")
elif key == "event_id":
row.append("")
elif key == "fees":
which_non_exam_key(non_exam, row, key)
elif key == "number_of_students":
row.append("")
elif key == "exam_received_ind":
row.append("")

out.writerow(row)

except AttributeError as error:
logging.error(error, exc_info=True)
return {"message": "Issue writing row to CSV ",
"key": key}, 500
if exam_type == 'all_bookings':
for non_exam in non_exams:
row = []
try:
for key in keys:
if key == "room_name":
write_booking_room(row, non_exam)
elif key == "invigilator_name":
row.append("")
elif key == "sbc_staff_invigilated":
row.append("")
elif key == "exam_received_date":
row.append("")
elif key == "exam_written_ind":
row.append("")
elif key == "exam_returned_date":
row.append("")
elif key == "office_name":
row.append(getattr(non_exam.office, key))
elif key == "exam_type_name":
row.append("Non Exam Booking")
elif key in booking_keys:
row.append(getattr(non_exam, key))
elif key in non_exam_keys:
which_non_exam_key(non_exam, row, key)
elif key == "exam_id":
row.append("")
elif key == "exam_name":
row.append("")
elif key == "examinee_name":
row.append("")
elif key == "event_id":
row.append("")
elif key == "fees":
which_non_exam_key(non_exam, row, key)
elif key == "number_of_students":
row.append("")
elif key == "exam_received_ind":
row.append("")

out.writerow(row)

except AttributeError as error:
logging.error(error, exc_info=True)
return {"message": "Issue writing row to CSV ",
"key": key}, 500

output = make_response(dest.getvalue())
output.headers["Content-Disposition"] = "attachment; filename=export.csv"
Expand All @@ -227,8 +231,10 @@ def get(self):


def write_booking_room(row, booking):
row.append(booking.room.room_name)

if booking.room is None:
row.append("")
else:
row.append(booking.room.room_name)

def write_room(row, exam):
if exam.booking and exam.booking.room:
Expand Down Expand Up @@ -299,7 +305,3 @@ def which_non_exam_key(booking, row, key):
row.append("N")
elif booking.fees == 'true':
row.append("Y")




43 changes: 34 additions & 9 deletions frontend/src/exams/generate-financial-report-modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
:no-close-on-backdrop="true"
ok-title="Submit"
ok-variant="primary"
hide-ok
@ok="submit"
@cancel="cancel"
hide-ok
hide-header
hide-cancel
size="md">
<b-container style="font-size:1.1rem; border-radius: 10px" class="mb-2 pb-3" fluid>
<b-row>
Expand Down Expand Up @@ -34,11 +34,28 @@
</b-row>
<b-row>
<b-col sm="4"><label>Exam Types:</label></b-col>
<b-col sm="6>">
<b-form-group>
<b-form-radio-group :options="options"
stacked
v-model="selectedExamType" />
<b-col sm="5.5>">
<b-form-group v-if="selectedExamFilter !== ''">
<b-dropdown id="exam_filter_types_wo_filter"
:text=this.selectedExamFilter
class="w-100 mb-3"
variant="primary"
v-model="selectedExamType">
<b-dropdown-item v-for="option in options"
@click="selectedExamType = option.value
selectedExamFilter = option.text"> {{ option.text }}</b-dropdown-item>
</b-dropdown>
</b-form-group>
<b-form-group v-else>
<b-dropdown id="exam_filter_types_w_filter"
text="Click for Filter Options"
class="w-100 mb-3"
variant="primary"
v-model="selectedExamType">
<b-dropdown-item v-for="option in options"
@click="selectedExamType = option.value
selectedExamFilter = option.text"> {{ option.text }}</b-dropdown-item>
</b-dropdown>
</b-form-group>
</b-col>
</b-row>
Expand All @@ -59,11 +76,13 @@
startDate: '',
endDate: '',
options: [
{text: 'All Booking Events', value: 'all'},
{text: 'ITA - Individual and Group ', value: 'ita'},
{text: 'All Exams', value: 'all_exams'},
{text: 'All Booking Events', value: 'all_bookings'},
{text: 'ITA Individual and Group Exams', value: 'ita'},
{text: 'All Non-ITA Exams', value: 'all_non_ita'},
],
selectedExamType: '',
selectedExamFilter: '',
}
},
methods: {
Expand All @@ -74,6 +93,10 @@
...mapMutations([
'toggleGenFinReport',
]),
cancel() {
this.selectedExamType = ''
this.selectedExamFilter = ''
},
submit() {
let form_start_date = moment.utc(this.startDate).format('YYYY-MM-DD')
let form_end_date = moment.utc(this.endDate).format('YYYY-MM-DD')
Expand All @@ -88,6 +111,7 @@
this.startDate = ''
this.endDate = ''
this.selectedExamType = ''
this.selectedExamFilter = ''
},
},
computed: {
Expand All @@ -99,6 +123,7 @@
return this.showGenFinReportModal
},
set(e) {
this.selectedExamFilter = ''
this.toggleGenFinReport(e)
}
},
Expand Down

0 comments on commit dd331a5

Please sign in to comment.