[UPDT] PAYROLL: Payroll contract delete method

This commit is contained in:
Horilla
2024-02-05 11:49:12 +05:30
parent 6c16072420
commit 425cf7a68f
5 changed files with 53 additions and 11 deletions

View File

@@ -1,8 +1,18 @@
{% load i18n %}
{% load static %}
{% include 'filter_tags.html' %}
<div class="oh-sticky-table">
{% if messages %}
<div class="oh-wrapper">
{% for message in messages %}
<div class="oh-alert-container">
<div class="oh-alert oh-alert--animated {{message.tags}}">
{{ message }}
</div>
</div>
{% endfor %}
</div>
{% endif %}
<div class="oh-sticky-table" style="max-height:56vh;">
<div class="oh-sticky-table__table">
<div class="oh-sticky-table__thead">
<div class="oh-sticky-table__tr">
@@ -75,10 +85,13 @@
></ion-icon>
</a>
<a
onclick = "event.preventDefault();event.stopPropagation(); confirm(`{% trans 'Do you want to delete this Contract?' %}`)"
onclick = "event.preventDefault();event.stopPropagation();"
class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
href="{% url 'delete-contract' contract.id %}"
title='{% trans "Delete" %}'
hx-confirm="{% trans 'Do you want to delete this Contract?' %}"
hx-post="{% url 'delete-contract-modal' contract.id %}?{{pd}}"
hx-target="#payroll-contract-container"
hx-swap="innerHTML"
title="{% trans 'Delete' %}"
>
<ion-icon
name="trash-outline"

View File

@@ -130,7 +130,12 @@
aria-label="create outline"
></ion-icon>{% trans "Edit" %}
</a>
<a href="{% url 'delete-contract' contract.id %}" class="oh-btn oh-btn--danger"style="width: 50%;">
<a
class="oh-btn oh-btn--danger"style="width: 50%;"
hx-confirm="{% trans 'Do you want to delete this Contract?' %}"
hx-post="{% url 'delete-contract-modal' contract.id %}?{{pd}}"
hx-target="#payroll-contract-container"
>
<ion-icon
name="trash-outline"
role="img"

View File

@@ -1,4 +1,15 @@
{% load i18n %} {% load attendancefilters %} {% include 'filter_tags.html' %}
{% if messages %}
<div class="oh-wrapper">
{% for message in messages %}
<div class="oh-alert-container">
<div class="oh-alert oh-alert--animated {{message.tags}}">
{{ message }}
</div>
</div>
{% endfor %}
</div>
{% endif %}
<div class="oh-card">
{% dynamic_regroup contracts by field as contract_grouper %} {% for contract_list in contract_grouper %}
@@ -90,11 +101,14 @@
></ion-icon>
</a>
<a
onclick = "event.preventDefault();event.stopPropagation(); confirm(`{% trans 'Do you want to delete this Contract?' %}`)"
class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
href="{% url 'delete-contract' contract.id %}"
title='{% trans "Delete" %}'
>
onclick = "event.preventDefault();event.stopPropagation();"
class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100"
hx-confirm="{% trans 'Do you want to delete this Contract?' %}"
hx-post="{% url 'delete-contract' contract.id %}?{{pd}}"
hx-target="#payroll-contract-container"
hx-swap="innerHTML"
title="{% trans 'Delete' %}"
>
<ion-icon
name="trash-outline"
role="img"

View File

@@ -29,6 +29,11 @@ urlpatterns = [
views.contract_delete,
name="delete-contract",
),
path(
"delete-contract-modal/<int:contract_id>",
views.contract_delete,
name="delete-contract-modal",
),
path("view-contract/", views.contract_view, name="view-contract"),
path(
"single-contract-view/<int:contract_id>/",

View File

@@ -136,6 +136,11 @@ def contract_delete(request, contract_id):
try:
Contract.objects.get(id=contract_id).delete()
messages.success(request, _("Contract deleted"))
request_path = request.path.split("/")
if "delete-contract-modal" in request_path:
return HttpResponse("<script>window.location.reload();</script>")
else:
return redirect(f"/payroll/contract-filter?{request.GET.urlencode()}")
except Contract.DoesNotExist:
messages.error(request, _("Contract not found."))
except ProtectedError: