From b86d11990a06298922819ff0e9378537625f1bb3 Mon Sep 17 00:00:00 2001 From: Horilla Date: Fri, 17 May 2024 11:17:19 +0530 Subject: [PATCH] [FIX] BASE: Shift and worktype hx create and delete issue, and both request cancelling issue fixes for employee who have no work info --- .../shift_request/htmx/requests.html | 11 +++-- .../shift_request/shift_request_nav.html | 1 + base/views.py | 49 +++++++++++++------ 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/base/templates/shift_request/htmx/requests.html b/base/templates/shift_request/htmx/requests.html index 3bd3f33a4..ed0cfa2b5 100755 --- a/base/templates/shift_request/htmx/requests.html +++ b/base/templates/shift_request/htmx/requests.html @@ -56,7 +56,7 @@
{% trans "Description" %}
{% trans "Comment" %}
{% trans "Actions" %}
- {% if perms.base.change_shiftrequest and shift_request.approved == False or request.user|is_reportingmanager %} + {% if perms.base.change_shiftrequest or request.user|is_reportingmanager %}
{% trans "Confirmation" %}
{% endif %} @@ -131,6 +131,11 @@ {% csrf_token %} + {% elif perms.base.change_shiftrequest or request.user|is_reportingmanager %} +
+ {% csrf_token %} + +
{% else %} {% endif %} @@ -297,10 +302,10 @@ >{% trans "Requested Till" %}
{% trans "Description" %}
{% trans "Comment" %}
- {% if perms.base.change_shiftrequest and shift_request.approved == False or request.user|is_reportingmanager %} + {% if perms.base.change_shiftrequest or request.user|is_reportingmanager %}
{% trans "Actions" %}
+
{% trans "Confirmation" %}
{% endif %} -
{% trans "Confirmation" %}
diff --git a/base/templates/shift_request/shift_request_nav.html b/base/templates/shift_request/shift_request_nav.html index 06243421b..f0ce32bac 100644 --- a/base/templates/shift_request/shift_request_nav.html +++ b/base/templates/shift_request/shift_request_nav.html @@ -25,6 +25,7 @@ hx-target="#view-container" id="filterForm" class="d-flex" + onsubmit = "event.preventDefault()" >
{% if data or allocated_data %} diff --git a/base/views.py b/base/views.py index 16990d121..2e4f3c50b 100644 --- a/base/views.py +++ b/base/views.py @@ -2698,6 +2698,9 @@ def work_type_request(request): except Exception as error: pass messages.success(request, _("Work type request added.")) + work_type_requests = WorkTypeRequest.objects.all() + if len(work_type_requests) == 1: + return HttpResponse("") form = WorkTypeRequestForm() context["form"] = form return render(request, "work_type_request/request_form.html", context=context) @@ -2720,10 +2723,14 @@ def work_type_request_cancel(request, id): ): work_type_request.canceled = True work_type_request.approved = False - work_type_request.employee_id.employee_work_info.work_type_id = ( - work_type_request.previous_work_type_id + work_info = EmployeeWorkInformation.objects.filter( + employee_id=work_type_request.employee_id ) - work_type_request.employee_id.employee_work_info.save() + if work_info.exists(): + work_type_request.employee_id.employee_work_info.work_type_id = ( + work_type_request.previous_work_type_id + ) + work_type_request.employee_id.employee_work_info.save() work_type_request.save() messages.success(request, _("Work type request has been rejected.")) notify.send( @@ -2946,7 +2953,12 @@ def work_type_request_delete(request, obj_id): ) elif hx_target and hx_target == "view-container": previous_data = request.GET.urlencode() - return redirect(f"/work-type-request-search?{previous_data}") + work_type_requests = WorkTypeRequest.objects.all() + if work_type_requests.exists(): + return redirect(f"/work-type-request-search?{previous_data}") + else: + return HttpResponse("") + elif hx_target and hx_target == "shift_target" and employee: return redirect(f"/employee/shift-tab/{employee.id}") else: @@ -3552,17 +3564,22 @@ def shift_request_cancel(request, id): ): shift_request.canceled = True shift_request.approved = False - shift_request.employee_id.employee_work_info.shift_id = ( - shift_request.previous_shift_id - ) - if shift_request.reallocate_to: + work_info = EmployeeWorkInformation.objects.filter( + employee_id=shift_request.employee_id + ) + if work_info.exists(): + shift_request.employee_id.employee_work_info.shift_id = ( + shift_request.previous_shift_id + ) + + if shift_request.reallocate_to and work_info.exists(): shift_request.reallocate_to.employee_work_info.shift_id = ( shift_request.shift_id ) shift_request.reallocate_to.employee_work_info.save() - - shift_request.employee_id.employee_work_info.save() + if work_info.exists(): + shift_request.employee_id.employee_work_info.save() shift_request.save() messages.success(request, _("Shift request rejected")) notify.send( @@ -3590,7 +3607,7 @@ def shift_request_cancel(request, id): ) return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) - return HttpResponse("You cant cancel the request") + return HttpResponse("You can't cancel the request") @login_required @@ -3606,10 +3623,14 @@ def shift_allocation_request_cancel(request, id): shift_request.reallocate_canceled = True shift_request.reallocate_approved = False - shift_request.employee_id.employee_work_info.shift_id = ( - shift_request.previous_shift_id + work_info = EmployeeWorkInformation.objects.filter( + employee_id=shift_request.employee_id ) - shift_request.employee_id.employee_work_info.save() + if work_info.exists(): + shift_request.employee_id.employee_work_info.shift_id = ( + shift_request.previous_shift_id + ) + shift_request.employee_id.employee_work_info.save() shift_request.save() messages.success(request, _("Shift request canceled")) notify.send(