Skip to content

Commit

Permalink
started on weekly approvals, added consultant and line manager names …
Browse files Browse the repository at this point in the history
…to payload
  • Loading branch information
delterr committed Apr 2, 2024
1 parent 149dd26 commit 34f9f1a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Binary file modified backend/flask_session/679eaac484e8efec851e5d02a21b12ac
Binary file not shown.
Binary file modified backend/flask_session/d809bf2dcbe2110e634be9cd9bce2102
Binary file not shown.
31 changes: 29 additions & 2 deletions backend/timesheets/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class ListWeeklyTimesheetsView(MethodView):
def get(self):
user_id = session.get("user_id")
consultant = Consultant.query.filter_by(id=user_id).first()
line_manager = LineManager.query.filter_by(username=consultant.line_manager)
print(consultant)

if consultant == None:
Expand All @@ -160,10 +161,35 @@ def get(self):
for timesheet in timesheets:
hours_worked = str(timedelta(seconds=timesheet.hours_worked))
day = f"{timesheet.day.day}/{timesheet.day.month}/{timesheet.day.year}"
json_dict[timesheet.id] = {"start_work": timesheet.start_work_time, "end_work": timesheet.end_work_time, "week_start": week_start, "hours_worked": hours_worked, "day": day}
json_dict[timesheet.id] = {"start_work": timesheet.start_work_time, "end_work": timesheet.end_work_time,
"week_start": week_start, "hours_worked": hours_worked, "day": day,
"consultant_name": f"{consultant.firstname} {consultant.lastname}", "line_manager_name": line_manager}
return jsonify(json_dict), 200


class WeeklyTimesheetsApprovalView(MethodView):
def post(self, consultant_username, flag):
user_id = session.get("user_id")
line_manager = LineManager.query.filter_by(id=user_id)
consultant = Consultant.query.filter_by(username=consultant_username)

week_start = datetime.today() - timedelta(days=datetime.today().weekday() % 7)
week_start = datetime(week_start.year, week_start.month, week_start.day)
week_start = f"{week_start.day}/{week_start.month}/{week_start.year}"
timesheets = Timesheet.query.filter_by(week_start_date=week_start, username=consultant_username).all()

for timesheet in timesheets :
if flag == "approve":
timesheet.status = "approved"
db.session.commit()
elif flag == "disapprove":
timesheet.status = "disapproved"
else:
return jsonify({"Error": "Invalid flag"}), 400

return jsonify("Success"), 200


class ListConsultantsView(MethodView):
def get(self):
user_id = session.get("user_id")
Expand Down Expand Up @@ -328,7 +354,8 @@ def post(self):
app.add_url_rule("/delete_timesheet/<timesheet_id>", view_func=timesheets_view, methods=["DELETE"])
app.add_url_rule("/list_timesheets", view_func=ListTimesheetsView.as_view("list_timesheets_view"), methods=["GET"])
app.add_url_rule("/list_weekly_timesheets", view_func=ListWeeklyTimesheetsView.as_view("list_weekly_timesheets_view"), methods=["GET"])
app.add_url_rule("/list_timesheets/<consultant_id>", view_func=ListConsultantTimesheetsView.as_view("list_consultant_timesheets_view"), methods=["GET"])
app.add_url_rule("/list_weekly_timesheets/<consultant_username>/<flag>", view_func=WeeklyTimesheetsApprovalView.as_view("list_weekly_timesheets_approval"), methods=["POST"])
app.add_url_rule("/list_timesheets/<consultant_id>", view_func=ListConsultantTimesheetsView.as_view("list_consultant_timesheets_viewpost"), methods=["GET"])
app.add_url_rule("/approve_timesheet/<timesheet_id>", view_func=TimesheetApprovalView.as_view("timesheet_approval_view"), methods=["POST"])
app.add_url_rule("/disapprove_timesheet/<timesheet_id>", view_func=TimesheetDisapprovalView.as_view("timesheet_disapproval_view"), methods=["POST"])

Expand Down

0 comments on commit 34f9f1a

Please sign in to comment.