[UPDT] OFFBOARDING: Restriction to update the form if its on the requested state
This commit is contained in:
@@ -8,6 +8,7 @@ import contextlib
|
||||
from typing import Any
|
||||
from django import forms
|
||||
from django.template.loader import render_to_string
|
||||
from django.contrib import messages
|
||||
from base.forms import ModelForm
|
||||
from base import thread_local_middleware
|
||||
from employee.forms import MultipleFileField
|
||||
@@ -263,13 +264,28 @@ class ResignationLetterForm(ModelForm):
|
||||
"is_active",
|
||||
]
|
||||
self.instance.employee_id = request.user.employee_get
|
||||
exclude = list(set(exclude))
|
||||
for field in exclude:
|
||||
del self.fields[field]
|
||||
|
||||
def save(self, commit: bool = ...) -> Any:
|
||||
instance = super().save(commit)
|
||||
request = getattr(thread_local_middleware._thread_locals, "request", None)
|
||||
if request and not request.user.has_perm("offboarding.add_offboardingemployee"):
|
||||
instance = self.instance
|
||||
if (
|
||||
not request.user.has_perm("offboarding.add_offboardingemployee")
|
||||
and instance.status == "requested"
|
||||
) or request.user.has_perm("add_offboardingemployee"):
|
||||
instance = super().save(commit)
|
||||
else:
|
||||
messages.info(
|
||||
request, "You cannot edit a request that has been rejected/approved"
|
||||
)
|
||||
|
||||
if (
|
||||
instance.status == "requested"
|
||||
and request
|
||||
and not request.user.has_perm("offboarding.add_offboardingemployee")
|
||||
):
|
||||
with contextlib.suppress(Exception):
|
||||
notify.send(
|
||||
request.user.employee_get,
|
||||
|
||||
@@ -28,23 +28,29 @@
|
||||
<div class="reisgn-status" style="display: inline;">{{ record.status|capfirst }}</div>
|
||||
</div>
|
||||
<div>
|
||||
{% if perms.offboarding.change_resignationletter %}
|
||||
<div class="oh-btn-group">
|
||||
{% if perms.offboarding.change_resignationletter %}
|
||||
<button type="button" hx-get="{% url 'send-mail-employee' record.employee_id.id %}" title="{% trans " Send
|
||||
Mail" %}" hx-target="#resignationModalBody" class="oh-btn oh-btn--light" data-toggle="oh-modal-toggle"
|
||||
data-target="#resignationModal" style="flex: 1 0 auto; width: 40px; height: 40.68px; padding: 0"
|
||||
onclick="event.stopPropagation()"><ion-icon name="mail-open-outline" role="img" class="md hydrated"
|
||||
aria-label="mail open outline"></ion-icon></button>
|
||||
aria-label="mail open outline"></ion-icon>
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
<a hx-get="{% url 'create-resignation-request' %}?instance_id={{ record.id }}" {% trans "Edit" %}
|
||||
class="oh-btn oh-btn--light" data-toggle="oh-modal-toggle" hx-target="#resignationModalBody"
|
||||
data-target="#resignationModal" style="flex: 1 0 auto; width: 40px; height: 40.68px; padding: 0"><ion-icon
|
||||
class="text-dark md hydrated" name="create-outline" role="img" aria-label="create outline"></ion-icon></a>
|
||||
{% if perms.offboarding.delete_resignationletter %}
|
||||
<a href="{% url 'delete-resignation-request' %}?letter_ids={{record.id}}" class="oh-btn oh-btn--light" {%
|
||||
trans "Delete" %} style="flex: 1 0 auto; width: 40px; height: 40.68px; padding: 0"
|
||||
onclick="return confirm('{% trans 'Do you want to delete this record' %}?')"><ion-icon
|
||||
class="text-danger md hydrated" name="trash-outline" role="img" aria-label="trash outline"></ion-icon></a>
|
||||
class="text-danger md hydrated" name="trash-outline" role="img" aria-label="trash outline"></ion-icon>
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user