2024-08-27 17:34:55 +05:30
|
|
|
from typing import Any
|
2024-08-30 14:51:21 +05:30
|
|
|
|
|
|
|
|
from django.contrib import messages
|
2024-08-27 17:34:55 +05:30
|
|
|
from django.http import HttpResponse
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
from django.urls import reverse_lazy
|
2024-09-03 17:18:01 +05:30
|
|
|
from django.utils.decorators import method_decorator
|
2024-08-27 17:34:55 +05:30
|
|
|
from django.utils.translation import gettext_lazy as _trans
|
|
|
|
|
|
2024-09-03 17:18:01 +05:30
|
|
|
from base.methods import filter_own_and_subordinate_recordes, is_reportingmanager
|
|
|
|
|
from horilla import horilla_middlewares
|
|
|
|
|
from horilla.decorators import login_required, permission_required
|
2024-08-30 14:51:21 +05:30
|
|
|
from horilla_views.generic.cbv import views
|
|
|
|
|
from pms import models
|
|
|
|
|
from pms.filters import BonusPointSettingFilter, EmployeeBonusPointFilter
|
|
|
|
|
from pms.forms import BonusPointSettingForm, EmployeeBonusPointForm
|
|
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
|
2024-08-30 14:51:21 +05:30
|
|
|
# ================Models for BonusPointSetting==============
|
2024-09-03 17:18:01 +05:30
|
|
|
@method_decorator(login_required, name="dispatch")
|
|
|
|
|
@method_decorator(permission_required("pms.view_bonuspointsetting"), name="dispatch")
|
2024-08-27 17:34:55 +05:30
|
|
|
class BonusPointSettingSectionView(views.HorillaSectionView):
|
|
|
|
|
"""
|
|
|
|
|
BonusPointSetting SectionView
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
nav_url = reverse_lazy("bonus-point-setting-nav")
|
|
|
|
|
view_url = reverse_lazy("bonus-point-setting-list-view")
|
|
|
|
|
view_container_id = "listContainer"
|
|
|
|
|
|
|
|
|
|
# script_static_paths = [
|
|
|
|
|
# "static/automation/automation.js",
|
|
|
|
|
# ]
|
|
|
|
|
|
|
|
|
|
template_name = "bonus/bonus_point_setting_section.html"
|
|
|
|
|
|
|
|
|
|
|
2024-09-03 17:18:01 +05:30
|
|
|
@method_decorator(login_required, name="dispatch")
|
|
|
|
|
@method_decorator(permission_required("pms.view_bonuspointsetting"), name="dispatch")
|
2024-08-27 17:34:55 +05:30
|
|
|
class BonusPointSettingNavView(views.HorillaNavView):
|
|
|
|
|
"""
|
|
|
|
|
BonusPointSetting nav view
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs) -> None:
|
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
self.create_attrs = f"""
|
|
|
|
|
hx-get="{reverse_lazy("create-bonus-point-setting")}"
|
|
|
|
|
hx-target="#genericModalBody"
|
|
|
|
|
data-toggle="oh-modal-toggle"
|
|
|
|
|
data-target="#genericModal"
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
nav_title = _trans("Bonus Point Setting")
|
|
|
|
|
search_url = reverse_lazy("bonus-point-setting-list-view")
|
|
|
|
|
search_swap_target = "#listContainer"
|
|
|
|
|
|
|
|
|
|
|
2024-09-03 17:18:01 +05:30
|
|
|
@method_decorator(login_required, name="dispatch")
|
|
|
|
|
@method_decorator(permission_required("pms.change_bonuspointsetting"), name="dispatch")
|
2024-08-27 17:34:55 +05:30
|
|
|
class BonusPointSettingFormView(views.HorillaFormView):
|
|
|
|
|
"""
|
|
|
|
|
BonusPointSettingForm View
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
form_class = BonusPointSettingForm
|
|
|
|
|
model = models.BonusPointSetting
|
|
|
|
|
new_display_title = _trans("Create Bonus Point Setting")
|
2024-08-30 14:51:21 +05:30
|
|
|
template_name = "bonus/bonus_form.html"
|
2024-08-27 17:34:55 +05:30
|
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
|
|
|
|
kwargs = super().get_form_kwargs()
|
|
|
|
|
instance = models.BonusPointSetting.objects.filter(pk=self.kwargs["pk"]).first()
|
|
|
|
|
kwargs["instance"] = instance
|
|
|
|
|
return kwargs
|
2024-08-30 14:51:21 +05:30
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
def get_context_data(self, **kwargs):
|
2024-08-30 14:51:21 +05:30
|
|
|
context = super().get_context_data(**kwargs)
|
2024-08-27 17:34:55 +05:30
|
|
|
return context
|
2024-08-30 14:51:21 +05:30
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
def form_invalid(self, form: Any) -> HttpResponse:
|
2024-08-30 14:51:21 +05:30
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
if not form.is_valid():
|
|
|
|
|
errors = form.errors.as_data()
|
|
|
|
|
return render(
|
|
|
|
|
self.request, self.template_name, {"form": form, "errors": errors}
|
|
|
|
|
)
|
|
|
|
|
return super().form_invalid(form)
|
2024-08-30 14:51:21 +05:30
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
def form_valid(self, form: BonusPointSettingForm) -> views.HttpResponse:
|
|
|
|
|
if form.is_valid():
|
|
|
|
|
message = "Bonus Point Setting added"
|
|
|
|
|
if form.instance.pk:
|
|
|
|
|
message = "Bonus Point Setting updated"
|
|
|
|
|
form.save()
|
|
|
|
|
|
|
|
|
|
messages.success(self.request, _trans(message))
|
|
|
|
|
return self.HttpResponse()
|
2024-08-30 14:51:21 +05:30
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
return super().form_valid(form)
|
|
|
|
|
|
|
|
|
|
|
2024-09-03 17:18:01 +05:30
|
|
|
@method_decorator(login_required, name="dispatch")
|
|
|
|
|
@method_decorator(permission_required("pms.view_bonuspointsetting"), name="dispatch")
|
2024-08-27 17:34:55 +05:30
|
|
|
class BonusPointSettingListView(views.HorillaListView):
|
|
|
|
|
"""
|
|
|
|
|
BnusPointSetting list view
|
|
|
|
|
"""
|
2024-08-30 14:51:21 +05:30
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
model = models.BonusPointSetting
|
|
|
|
|
search_url = reverse_lazy("bonus-point-setting-list-view")
|
|
|
|
|
filter_class = BonusPointSettingFilter
|
|
|
|
|
action_method = "action_template"
|
|
|
|
|
|
|
|
|
|
columns = [
|
|
|
|
|
("Model", "get_model_display"),
|
2024-08-30 14:51:21 +05:30
|
|
|
("Applicable For", "get_applicable_for_display"),
|
2024-08-27 17:34:55 +05:30
|
|
|
("Bonus For", "get_bonus_for_display"),
|
|
|
|
|
("Condition", "get_condition"),
|
2024-08-30 14:51:21 +05:30
|
|
|
("Points", "points"),
|
|
|
|
|
("Is Active", "is_active_toggle"),
|
2024-08-27 17:34:55 +05:30
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2024-08-30 14:51:21 +05:30
|
|
|
# ================Models for EmployeeBonusPoint==============
|
|
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
|
|
|
|
|
class EmployeeBonusPointSectionView(views.HorillaSectionView):
|
|
|
|
|
"""
|
|
|
|
|
EmployeeBonusPoint SectionView
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
nav_url = reverse_lazy("employee-bonus-point-nav")
|
|
|
|
|
view_url = reverse_lazy("employee-bonus-point-list-view")
|
|
|
|
|
view_container_id = "listContainer"
|
|
|
|
|
|
|
|
|
|
# script_static_paths = [
|
|
|
|
|
# "static/automation/automation.js",
|
|
|
|
|
# ]
|
|
|
|
|
|
|
|
|
|
template_name = "bonus/employee_bonus_point_section.html"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EmployeeBonusPointNavView(views.HorillaNavView):
|
|
|
|
|
"""
|
|
|
|
|
BonusPoint nav view
|
|
|
|
|
"""
|
|
|
|
|
|
2024-08-30 14:51:21 +05:30
|
|
|
template_name = "bonus/bonus_point_nav.html"
|
|
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
def __init__(self, *args, **kwargs) -> None:
|
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
self.create_attrs = f"""
|
|
|
|
|
hx-get="{reverse_lazy("create-employee-bonus-point")}"
|
|
|
|
|
hx-target="#genericModalBody"
|
|
|
|
|
data-toggle="oh-modal-toggle"
|
|
|
|
|
data-target="#genericModal"
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
nav_title = _trans("Employee Bonus Point ")
|
|
|
|
|
search_url = reverse_lazy("employee-bonus-point-list-view")
|
|
|
|
|
search_swap_target = "#listContainer"
|
2024-08-30 14:51:21 +05:30
|
|
|
group_by_fields = [
|
|
|
|
|
("employee_id", _trans("Employee")),
|
|
|
|
|
(
|
|
|
|
|
"employee_id__employee_work_info__reporting_manager_id",
|
|
|
|
|
_trans("Reporting Manager"),
|
|
|
|
|
),
|
|
|
|
|
("employee_id__employee_work_info__department_id", _trans("Department")),
|
|
|
|
|
("employee_id__employee_work_info__job_position_id", _trans("Job Position")),
|
|
|
|
|
(
|
|
|
|
|
"employee_id__employee_work_info__employee_type_id",
|
|
|
|
|
_trans("Employement Type"),
|
|
|
|
|
),
|
|
|
|
|
("employee_id__employee_work_info__company_id", _trans("Company")),
|
|
|
|
|
]
|
2024-08-27 17:34:55 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
class EmployeeBonusPointFormView(views.HorillaFormView):
|
|
|
|
|
"""
|
|
|
|
|
BonusPointForm View
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
form_class = EmployeeBonusPointForm
|
|
|
|
|
model = models.EmployeeBonusPoint
|
|
|
|
|
new_display_title = _trans("Create Employee Bonus Point ")
|
|
|
|
|
# template_name = "bonus/bonus_form.html"
|
2024-08-30 14:51:21 +05:30
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
def get_context_data(self, **kwargs):
|
2024-08-30 14:51:21 +05:30
|
|
|
context = super().get_context_data(**kwargs)
|
2024-08-27 17:34:55 +05:30
|
|
|
return context
|
2024-08-30 14:51:21 +05:30
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
def form_invalid(self, form: Any) -> HttpResponse:
|
2024-08-30 14:51:21 +05:30
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
if not form.is_valid():
|
|
|
|
|
errors = form.errors.as_data()
|
|
|
|
|
return render(
|
|
|
|
|
self.request, self.template_name, {"form": form, "errors": errors}
|
|
|
|
|
)
|
|
|
|
|
return super().form_invalid(form)
|
2024-08-30 14:51:21 +05:30
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
def form_valid(self, form: EmployeeBonusPointForm) -> views.HttpResponse:
|
|
|
|
|
if form.is_valid():
|
|
|
|
|
message = "Bonus Point added"
|
|
|
|
|
if form.instance.pk:
|
|
|
|
|
message = "Bonus Point updated"
|
|
|
|
|
form.save()
|
|
|
|
|
messages.success(self.request, _trans(message))
|
|
|
|
|
return self.HttpResponse()
|
2024-08-30 14:51:21 +05:30
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
return super().form_valid(form)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EmployeeBonusPointListView(views.HorillaListView):
|
|
|
|
|
"""
|
|
|
|
|
BnusPoint list view
|
|
|
|
|
"""
|
2024-08-30 14:51:21 +05:30
|
|
|
|
2024-09-03 17:18:01 +05:30
|
|
|
request = getattr(horilla_middlewares._thread_locals, "request", None)
|
|
|
|
|
|
2024-08-27 17:34:55 +05:30
|
|
|
model = models.EmployeeBonusPoint
|
|
|
|
|
search_url = reverse_lazy("employee-bonus-point-list-view")
|
|
|
|
|
filter_class = EmployeeBonusPointFilter
|
2024-09-03 17:18:01 +05:30
|
|
|
if is_reportingmanager(request):
|
|
|
|
|
action_method = "action_template"
|
2024-08-30 14:51:21 +05:30
|
|
|
bulk_update_fields = [
|
|
|
|
|
"employee_id",
|
|
|
|
|
"bonus_point",
|
|
|
|
|
"based_on",
|
|
|
|
|
]
|
2024-08-27 17:34:55 +05:30
|
|
|
|
|
|
|
|
columns = [
|
|
|
|
|
("Employee", "employee_id"),
|
|
|
|
|
("Bonus Point", "bonus_point"),
|
2024-08-30 14:51:21 +05:30
|
|
|
("Based On", "based_on"),
|
2024-08-27 17:34:55 +05:30
|
|
|
]
|
2024-09-03 17:18:01 +05:30
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
|
queryset = super().get_queryset()
|
|
|
|
|
request = getattr(horilla_middlewares._thread_locals, "request", None)
|
|
|
|
|
if is_reportingmanager(request):
|
|
|
|
|
return filter_own_and_subordinate_recordes(
|
|
|
|
|
request, queryset, perm="pms.view_employeebonuspoint"
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
return queryset.filter(employee_id=request.user.employee_get)
|