[ADD] EMPLOYEE: Display online employees

This commit is contained in:
Horilla
2024-01-31 11:57:05 +05:30
parent d01211ff58
commit 91811b39f9
5 changed files with 93 additions and 43 deletions

View File

@@ -5,7 +5,7 @@ This module is used to register models for employee app
"""
import datetime as dtime
from datetime import date, datetime
from datetime import date, datetime, timedelta
import json
import threading
import time
@@ -20,6 +20,7 @@ from django.utils.translation import gettext as _
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 horilla_audit.models import HorillaAuditLog, HorillaAuditInfo
from horilla_audit.methods import get_diff
from base.models import (
@@ -282,6 +283,25 @@ class Employee(models.Model):
)
return f"{self.employee_first_name} {last_name}"
def check_online(self):
"""
This method is used to check the user in online users or not
"""
from attendance.models import Attendance
request = getattr(thread_local_middleware._thread_locals, "request", None)
if not getattr(request, "working_employees", None):
today = datetime.now().date()
yesterday = today - timedelta(days=1)
working_employees = Attendance.objects.filter(
attendance_date__gte=yesterday,
attendance_date__lte=today,
attendance_clock_out_date__isnull=True,
).values_list("employee_id", flat=True)
setattr(request, "working_employees", working_employees)
working_employees = request.working_employees
return self.id in working_employees
class Meta:
"""
Recruitment model
@@ -569,7 +589,7 @@ class Policy(models.Model):
title = models.CharField(max_length=50)
body = models.TextField()
is_visible_to_all = models.BooleanField(default=True)
specific_employees = models.ManyToManyField(Employee, blank=True,editable=False)
specific_employees = models.ManyToManyField(Employee, blank=True, editable=False)
attachments = models.ManyToManyField(PolicyMultipleFile, blank=True)
company_id = models.ManyToManyField(Company, blank=True)
@@ -581,16 +601,26 @@ class Policy(models.Model):
class BonusPoint(models.Model):
CONDITIONS =[
('==',_('equals')),
('>',_('grater than')),
('<',_('less than')),
('>=',_('greater than or equal')),
('<=',_('less than or equal')),
CONDITIONS = [
("==", _("equals")),
(">", _("grater than")),
("<", _("less than")),
(">=", _("greater than or equal")),
("<=", _("less than or equal")),
]
employee_id = models.OneToOneField(Employee, on_delete=models.CASCADE ,blank=True, null=True, related_name='bonus_point')
points = models.IntegerField(default=0, help_text="Use negative numbers to reduce points.")
encashment_condition = models.CharField(max_length=100,choices = CONDITIONS,blank=True, null=True)
employee_id = models.OneToOneField(
Employee,
on_delete=models.CASCADE,
blank=True,
null=True,
related_name="bonus_point",
)
points = models.IntegerField(
default=0, help_text="Use negative numbers to reduce points."
)
encashment_condition = models.CharField(
max_length=100, choices=CONDITIONS, blank=True, null=True
)
redeeming_points = models.IntegerField(blank=True, null=True)
reason = models.TextField(blank=True, null=True)
history = HorillaAuditLog(
@@ -599,38 +629,35 @@ class BonusPoint(models.Model):
HorillaAuditInfo,
],
)
def __str__(self):
return f"{self.employee_id} - {self.points} Points"
def tracking(self):
"""
This method is used to return the tracked history of the instance
"""
return get_diff(self)
@receiver(post_save, sender=Employee)
def bonus_post_save(sender, instance, **_kwargs):
if not BonusPoint.objects.filter(employee_id__id = instance.id).exists():
BonusPoint.objects.create(
employee_id = instance
)
if not BonusPoint.objects.filter(employee_id__id=instance.id).exists():
BonusPoint.objects.create(employee_id=instance)
class BonusPointThreading(threading.Thread):
def run(self):
time.sleep(5)
employees = Employee.objects.all()
try:
for employee in employees:
if not BonusPoint.objects.filter(employee_id__id = employee.id).exists():
BonusPoint.objects.create(
employee_id = employee
)
if not BonusPoint.objects.filter(employee_id__id=employee.id).exists():
BonusPoint.objects.create(employee_id=employee)
except:
pass
try:
try:
BonusPointThreading().start()
except:
pass
@@ -642,10 +669,10 @@ class Actiontype(models.Model):
"""
choice_actions = [
("warning", trans("Warning")),
("suspension", trans("Suspension")),
("dismissal", trans("Dismissal")),
]
("warning", trans("Warning")),
("suspension", trans("Suspension")),
("dismissal", trans("Dismissal")),
]
title = models.CharField(max_length=50)
action_type = models.CharField(max_length=30, choices=choice_actions)
@@ -662,9 +689,11 @@ class DisciplinaryAction(models.Model):
employee_id = models.ManyToManyField(Employee)
action = models.ForeignKey(Actiontype, on_delete=models.CASCADE)
description = models.TextField()
days = models.IntegerField(null=True, blank = True)
days = models.IntegerField(null=True, blank=True)
start_date = models.DateField(null=True)
attachment = models.FileField(upload_to="employee/discipline", null=True, blank = True)
attachment = models.FileField(
upload_to="employee/discipline", null=True, blank=True
)
company_id = models.ManyToManyField(Company, blank=True)
objects = HorillaCompanyManager()

View File

@@ -111,10 +111,17 @@
{% endif %}
/>
</div>
{% if employee.check_online %}
<span
class="oh-profile__active-badge oh-profile__active-badge--secondary"
title="{% trans 'Active' %}">
class="oh-profile__active-badge oh-profile__active-badge--secondary" style="background-color: yellowgreen;"
title="{% trans 'Online' %}">
</span>
{% else %}
<span
class="oh-profile__active-badge oh-profile__active-badge--secondary" style="background-color: rgba(128, 128, 128, 0.482);"
title="{% trans 'Offline' %}">
</span>
{% endif %}
</div>
<div class="oh-profile__info-container">
<h1 class="oh-profile__info-name">{{employee}}</h1>
@@ -290,7 +297,7 @@
<li data-cell-index="10" data-cell-title="{% trans "Bonus Points" %}" class="oh-general__tab">
<a
hx-get={% url 'bonus-points-tab' employee.id %}
hx-target="#resignation_hx_target"
hx-target="#bonus_points_target"
data-action="general-tab"
data-target="#bonus_points_target"
class="oh-general__tab-link"
@@ -335,7 +342,7 @@
class="oh-general__tab-target oh-profile__info-tab mb-4 d-none"
id="bonus_points_target"
>
{% include "tabs/bonus_points.html" %}
{% comment %} {% include "tabs/bonus_points.html" %} {% endcomment %}
</div>
<div
class="oh-general__tab-target oh-profile__info-tab mt-3 mb-4 d-none"

View File

@@ -122,10 +122,17 @@
{% endif %}
/>
</div>
{% if employee.check_online %}
<span
class="oh-profile__active-badge oh-profile__active-badge--secondary"
title="{% trans 'Active' %}">
class="oh-profile__active-badge oh-profile__active-badge--secondary" style="background-color: yellowgreen;"
title="{% trans 'Online' %}">
</span>
{% else %}
<span
class="oh-profile__active-badge oh-profile__active-badge--secondary" style="background-color: rgba(128, 128, 128, 0.482);"
title="{% trans 'Offline' %}">
</span>
{% endif %}
</div>
<div class="oh-profile__info-container">
<h1 class="oh-profile__info-name">{{employee}}</h1>

View File

@@ -5,14 +5,14 @@
<div class="d-flex flex-row-reverse p-0">
<span class="ml-3 mr-3" onclick="$('[name=working_today]').val('false'); $('[name=working_today]').first().change(); $('.filterButton').click()" style="cursor: pointer;margin-left: 10px;">
<div class="d-flex flex-row-reverse">
<span class="m-3" onclick="$('[name=working_today]').val('false'); $('[name=working_today]').first().change(); $('.filterButton').click()" style="cursor: pointer;margin-left: 10px;">
<span class="oh-dot oh-dot--small me-1" style="background-color:rgba(128, 128, 128, 0.482)"></span>
{% trans "Not-working" %}
{% trans "Offline" %}
</span>
<span class="ml-3 mr-3" onclick="$('[name=working_today]').val('true'); $('[name=working_today]').first().change(); $('.filterButton').click()" style="cursor: pointer;margin-left: 10px;">
<span class="m-3" onclick="$('[name=working_today]').val('true'); $('[name=working_today]').first().change(); $('.filterButton').click()" style="cursor: pointer;margin-left: 10px;">
<span class="oh-dot oh-dot--small me-1" style="background-color:yellowgreen"></span>
{% trans "Now-Working" %}
{% trans "Online" %}
</span>
</div>
{% if messages %}
@@ -58,6 +58,13 @@
<span class="oh-kanban-card__title">{{emp}}</span>
<span class="oh-kanban-card__subtitle">{{emp.email}}</span><br>
<span class="oh-kanban-card__subtitle">{{emp.employee_work_info.job_position_id}}</span>
<div class="oh-kanban-card__subtitle">
{% if emp.check_online %}
<span class="oh-dot oh-dot--small me-1" style="background-color:yellowgreen"></span> {% trans "Online" %}
{% else %}
<span class="oh-dot oh-dot--small me-1" style="background-color:rgba(128, 128, 128, 0.482)"></span> {% trans "Offline" %}
{% endif %}
</div>
</div>
</a>
{% if perms.employee.change_employee or perms.employee.delete_employee or request.user|check_manager:emp %}

View File

@@ -785,7 +785,7 @@
<a
href="{% url 'offboarding-pipeline' %}"
class="oh-sidebar__submenu-link"
>{% trans "Exist Process" %}</a
>{% trans "Exit Process" %}</a
>
</li>
{% if perms.offboarding.view_resignationletter and enabled_resignation_request %}