[UPDT] EMPPLOYEE: Hours option on disciplinary action
This commit is contained in:
@@ -26,9 +26,10 @@ import re
|
||||
from django import forms
|
||||
from django.db.models import Q
|
||||
from django.contrib.auth.models import User
|
||||
from django.forms import DateInput, ModelChoiceField, TextInput
|
||||
from django.forms import DateInput, TextInput
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy as trans
|
||||
from django.template.loader import render_to_string
|
||||
from base import thread_local_middleware
|
||||
from horilla.decorators import logger
|
||||
from employee.models import (
|
||||
@@ -589,7 +590,16 @@ class DisciplinaryActionForm(ModelForm):
|
||||
self.fields["action"].queryset.values_list("id", "title")
|
||||
)
|
||||
self.fields["action"].choices = action_choices
|
||||
self.fields["action"].choices += [("create", _("Create new action type "))]
|
||||
if self.instance.pk is None:
|
||||
self.fields["action"].choices += [("create", _("Create new action type "))]
|
||||
|
||||
def as_p(self):
|
||||
"""
|
||||
Render the form fields as HTML table rows with Bootstrap styling.
|
||||
"""
|
||||
context = {"form": self}
|
||||
table_html = render_to_string("common_form.html", context)
|
||||
return table_html
|
||||
|
||||
|
||||
class ActiontypeForm(ModelForm):
|
||||
|
||||
@@ -7,7 +7,7 @@ This module is used to register models for employee app
|
||||
|
||||
import datetime as dtime
|
||||
from datetime import date, datetime, timedelta
|
||||
from typing import Any
|
||||
from typing import Any, Iterable
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User, Permission
|
||||
@@ -19,6 +19,7 @@ from django.core.exceptions import ValidationError
|
||||
from django.core.files.storage import default_storage
|
||||
from simple_history.models import HistoricalRecords
|
||||
from base import thread_local_middleware
|
||||
from base.models import validate_time_format
|
||||
from horilla_audit.models import HorillaAuditLog, HorillaAuditInfo
|
||||
from horilla_audit.methods import get_diff
|
||||
from base.models import (
|
||||
@@ -344,7 +345,7 @@ class Employee(models.Model):
|
||||
This method is used to get last send mail
|
||||
"""
|
||||
from base.models import EmailLog
|
||||
|
||||
|
||||
return (
|
||||
EmailLog.objects.filter(to__icontains=self.get_mail())
|
||||
.order_by("-created_at")
|
||||
@@ -591,7 +592,7 @@ class EmployeeNote(models.Model):
|
||||
related_name="employee_name",
|
||||
)
|
||||
title = models.CharField(max_length=50, null=True, verbose_name=_("Title"))
|
||||
description = models.TextField(verbose_name=_("Description"),max_length=255)
|
||||
description = models.TextField(verbose_name=_("Description"), max_length=255)
|
||||
created_at = models.DateTimeField(
|
||||
auto_now_add=True,
|
||||
verbose_name=_("Created At"),
|
||||
@@ -655,7 +656,7 @@ class BonusPoint(models.Model):
|
||||
max_length=100, choices=CONDITIONS, blank=True, null=True
|
||||
)
|
||||
redeeming_points = models.IntegerField(blank=True, null=True)
|
||||
reason = models.TextField(blank=True, null=True,max_length=255)
|
||||
reason = models.TextField(blank=True, null=True, max_length=255)
|
||||
history = HorillaAuditLog(
|
||||
related_name="history_set",
|
||||
bases=[
|
||||
@@ -678,7 +679,6 @@ class BonusPoint(models.Model):
|
||||
BonusPoint.objects.create(employee_id=instance)
|
||||
|
||||
|
||||
|
||||
class Actiontype(models.Model):
|
||||
"""
|
||||
Action type model
|
||||
@@ -702,10 +702,18 @@ class DisciplinaryAction(models.Model):
|
||||
Disciplinary model
|
||||
"""
|
||||
|
||||
employee_id = models.ManyToManyField(Employee)
|
||||
choices = [("days", "Days"), ("hours", "In Hours")]
|
||||
employee_id = models.ManyToManyField(Employee, verbose_name="Employee")
|
||||
action = models.ForeignKey(Actiontype, on_delete=models.CASCADE)
|
||||
description = models.TextField(max_length=255)
|
||||
days = models.IntegerField(null=True, blank=True)
|
||||
unit_in = models.CharField(max_length=10, choices=choices,default="days")
|
||||
days = models.IntegerField(null=True, default=2)
|
||||
hours = models.CharField(
|
||||
max_length=6,
|
||||
default="00:00",
|
||||
null=True,
|
||||
validators=[validate_time_format],
|
||||
)
|
||||
start_date = models.DateField(null=True)
|
||||
attachment = models.FileField(
|
||||
upload_to="employee/discipline", null=True, blank=True
|
||||
|
||||
@@ -171,7 +171,7 @@ def create_actions(request):
|
||||
"""
|
||||
Method is used to create Disciplinaryaction
|
||||
"""
|
||||
form = DisciplinaryActionForm(request.GET)
|
||||
form = DisciplinaryActionForm(initial=request.GET)
|
||||
employees = []
|
||||
if request.method == "POST":
|
||||
form = DisciplinaryActionForm(request.POST, request.FILES)
|
||||
|
||||
@@ -53,13 +53,20 @@
|
||||
</div>
|
||||
{% if i.action.action_type == 'suspension' %}
|
||||
<div data-cell-index="1" class="oh-sticky-table__td">{{ i.action }}
|
||||
<p class="fw-bold mt-2">{% trans "Suspended for" %} {{ i.days }} {% trans "days." %}</p>
|
||||
<p class="fw-bold mt-2">{% trans "Suspended for" %}
|
||||
{% if i.unit_in == "days" %}
|
||||
{{ i.days }} {% trans "days" %}.
|
||||
{% else %}
|
||||
{{ i.hours }} {% trans "hours" %}.
|
||||
{% endif %}
|
||||
</p>
|
||||
|
||||
</div>
|
||||
{% else %}
|
||||
<div data-cell-index="1" class="oh-sticky-table__td">{{ i.action }}</div>
|
||||
{% endif %}
|
||||
|
||||
{% if i.action.action_type == 'suspension' %}
|
||||
{% if i.action.action_type == 'suspension' and i.unit_in == "days" %}
|
||||
<div data-cell-index="2" class="oh-sticky-table__td">
|
||||
<span class="dateformat_changer">{{ i.start_date }}</span>
|
||||
  to  <span class="dateformat_changer">{{ i.start_date | add_days:i.days }}</span>
|
||||
@@ -187,7 +194,7 @@
|
||||
function actionTypeChange(selectElement) {
|
||||
var selectedActiontype = selectElement.val();
|
||||
var parentForm = selectElement.parents().closest("form");
|
||||
if (selectedActiontype !== "create") {
|
||||
if (selectedActiontype !== "create" && selectedActiontype) {
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: "{% url 'action-type-details' %}",
|
||||
@@ -196,17 +203,34 @@
|
||||
"action_type": selectedActiontype,
|
||||
},
|
||||
success: function (response) {
|
||||
console.log(response.action_type);
|
||||
|
||||
// Check if the response.action_type is "suspension"
|
||||
$("#id_unit_in").change(function (e) {
|
||||
e.preventDefault();
|
||||
if (this.value == "days") {
|
||||
parentForm.find('#id_days').parent().show();
|
||||
parentForm.find('#id_hours').parent().hide();
|
||||
parentForm.find('[name=days]').prop('required', true);
|
||||
}else{
|
||||
parentForm.find('#id_hours').parent().show();
|
||||
parentForm.find('#id_days').parent().hide();
|
||||
parentForm.find('[name=days]').prop('required', false);
|
||||
}
|
||||
});
|
||||
if (response.action_type === "suspension") {
|
||||
// Show the 'days' field
|
||||
parentForm.find('#daysDiv').show();
|
||||
parentForm.find('[name=days]').prop('required', true);
|
||||
} else {
|
||||
parentForm.find('#id_unit_in').parent().show();
|
||||
parentForm.find('#id_hours').parent().show();
|
||||
$("#id_unit_in").change()
|
||||
} else {
|
||||
// Hide the 'days' field
|
||||
parentForm.find('#daysDiv').hide();
|
||||
$("#id_unit_in").change()
|
||||
parentForm.find('#id_days').parent().hide();
|
||||
parentForm.find('#id_unit_in').parent().hide();
|
||||
parentForm.find('#id_hours').parent().hide();
|
||||
parentForm.find('[name=days]').prop('required', false);
|
||||
}
|
||||
|
||||
},
|
||||
});
|
||||
}else{
|
||||
|
||||
@@ -23,43 +23,7 @@
|
||||
>
|
||||
{% csrf_token %}
|
||||
|
||||
<div id="employeeIdDiv">
|
||||
<label class="oh-input__label" for="{{form.employee_id.id_for_label}}"
|
||||
>{% trans "Employee" %}</label
|
||||
>
|
||||
{{ form.employee_id }}
|
||||
</div>
|
||||
<div id="actionDiv">
|
||||
<label class="oh-input__label" for="{{form.action.id_for_label}}"
|
||||
>{% trans "Action" %}</label
|
||||
>
|
||||
{{ form.action }}
|
||||
</div>
|
||||
<div id="daysDiv" style="display: none">
|
||||
<label class="oh-input__label" for="{{form.days.id_for_label}}"
|
||||
>{% trans "Days" %}</label
|
||||
>
|
||||
{{ form.days }}
|
||||
</div>
|
||||
<div id="startdateDiv">
|
||||
<label class="oh-input__label" for="{{form.start_date.id_for_label}}"
|
||||
>{% trans "Action Date" %}</label
|
||||
>
|
||||
{{ form.start_date }}
|
||||
</div>
|
||||
|
||||
<div id="descriptionDiv">
|
||||
<label class="oh-input__label" for="{{form.description.id_for_label}}"
|
||||
>{% trans "Description" %}</label
|
||||
>
|
||||
{{ form.description }}
|
||||
</div>
|
||||
<div id="attachmentDiv">
|
||||
<label class="oh-input__label" for="{{form.attachment.id_for_label}}"
|
||||
>{% trans "Attachment" %}</label
|
||||
>
|
||||
{{ form.attachment }}
|
||||
</div>
|
||||
{{form.as_p}}
|
||||
|
||||
<button type="submit" class="oh-btn oh-btn--secondary">
|
||||
{% trans "Submit" %}
|
||||
@@ -75,4 +39,8 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
$('#id_days').parent().hide();
|
||||
$('#id_unit_in').parent().hide();
|
||||
$('#id_hours').parent().hide();
|
||||
$('[name=days]').prop('required', false);
|
||||
</script>
|
||||
|
||||
@@ -17,33 +17,9 @@
|
||||
method="post"
|
||||
hx-encoding="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<div id="employeeIdDiv">
|
||||
<label class="oh-input__label" for="{{form.employee_id.id_for_label}}">{% trans "Employee" %}</label>
|
||||
{{ form.employee_id }}
|
||||
</div>
|
||||
<div id="actionDiv">
|
||||
<label class="oh-input__label" for="{{form.action.id_for_label}}">{% trans "Action" %}</label>
|
||||
{{ form.action }}
|
||||
</div>
|
||||
<div id="daysDiv" style="display: none;">
|
||||
<label class="oh-input__label" for="{{form.days.id_for_label}}">{% trans "Days" %}</label>
|
||||
{{ form.days }}
|
||||
</div>
|
||||
|
||||
<div id="startdateDiv">
|
||||
<label class="oh-input__label" for="{{form.start_date.id_for_label}}">{% trans "Action Date" %}</label>
|
||||
{{ form.start_date }}
|
||||
</div>
|
||||
|
||||
<div id="descriptionDiv">
|
||||
<label class="oh-input__label" for="{{form.description.id_for_label}}">{% trans "Description" %}</label>
|
||||
{{ form.description }}
|
||||
</div>
|
||||
<div id="attachmentDiv">
|
||||
<label class="oh-input__label" for="{{form.attachment.id_for_label}}">{% trans "Attachment" %}</label>
|
||||
{{ form.attachment }}
|
||||
</div>
|
||||
|
||||
<button type="submit" class="oh-btn oh-btn--secondary">{% trans "Submit" %}</button>
|
||||
{{form.as_p}}
|
||||
</form>
|
||||
|
||||
<script>
|
||||
$("#id_action").change()
|
||||
</script>
|
||||
@@ -112,6 +112,27 @@
|
||||
/>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if perms.change_employee %}
|
||||
{% if employee.employee_user_id.is_active %}
|
||||
<form action = "{% url 'employee-account-block-unblock' employee.id %}"
|
||||
onsubmit="return confirm('{% trans "Do you really want to prevent this employee from accessing and logging into this webpage?" %}');"
|
||||
>
|
||||
{% csrf_token %}
|
||||
<button type="submit" style=" width: 30px; height: 29px; margin-right: 22px; border: none; background: transparent;" title="{% trans 'Block Account' %}">
|
||||
<img src="{% static 'images/ui/block-user.png' %}" style="width: 26px; height: 25px; " >
|
||||
</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<form action = "{% url 'employee-account-block-unblock' employee.id %}"
|
||||
onsubmit="return confirm('{% trans "Do you really want to allow this employee to access and log into this webpage?" %}');"
|
||||
>
|
||||
{% csrf_token %}
|
||||
<button type="submit" style=" width: 30px; height: 29px; margin-right: 22px; border: none; background: transparent;" title="{% trans 'Un-Block Account' %}">
|
||||
<img src="{% static 'images/ui/unlock.png' %}" style="width: 30px; height: 27px; " >
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-12 col-md-12 col-lg-4">
|
||||
|
||||
@@ -104,6 +104,11 @@ urlpatterns = [
|
||||
views.save_employee_bulk_update,
|
||||
name="save-employee-bulk-update",
|
||||
),
|
||||
path(
|
||||
"employee-account-block-unblock/<int:emp_id>/",
|
||||
views.employee_account_block_unblock,
|
||||
name="employee-account-block-unblock",
|
||||
),
|
||||
path(
|
||||
"employee-bulk-delete", views.employee_bulk_delete, name="employee-bulk-delete"
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user