diff --git a/horilla_widgets/widgets/select_widgets.py b/horilla_widgets/widgets/select_widgets.py index bf859790c..88e81ea9f 100644 --- a/horilla_widgets/widgets/select_widgets.py +++ b/horilla_widgets/widgets/select_widgets.py @@ -35,6 +35,7 @@ class HorillaMultiSelectWidget(forms.Widget): filter_template_path=None, instance=None, required=False, + form=None, **kwargs ) -> None: self.filter_route_name = filter_route_name @@ -43,6 +44,7 @@ class HorillaMultiSelectWidget(forms.Widget): self.filter_instance_contex_name = filter_instance_contex_name self.filter_template_path = filter_template_path self.instance = instance + self.form = form super().__init__() template_name = "horilla_widgets/horilla_multiselect_widget.html" @@ -55,9 +57,17 @@ class HorillaMultiSelectWidget(forms.Widget): field = self.choices.field context["queryset"] = queryset context["field_name"] = name - if self.instance and self.instance.pk: + if self.form and name in self.form.data: + initial = self.form.data.getlist(name) + context["initial"] = initial + elif value: + context["initial"] = value + + elif self.instance and self.instance.pk: initial = list(getattr(self.instance, name).values_list("id", flat=True)) context["initial"] = initial + else: + context["initial"] = [] context["field"] = field context["self"] = self context["filter_template_path"] = self.filter_template_path diff --git a/pms/cbvs.py b/pms/cbvs.py index 3f604dca6..9d5d084dc 100644 --- a/pms/cbvs.py +++ b/pms/cbvs.py @@ -4,8 +4,12 @@ from django.contrib import messages from django.http import HttpResponse from django.shortcuts import render from django.urls import reverse_lazy +from django.utils.decorators import method_decorator from django.utils.translation import gettext_lazy as _trans +from base.methods import filter_own_and_subordinate_recordes, is_reportingmanager +from horilla import horilla_middlewares +from horilla.decorators import login_required, permission_required from horilla_views.generic.cbv import views from pms import models from pms.filters import BonusPointSettingFilter, EmployeeBonusPointFilter @@ -13,6 +17,8 @@ from pms.forms import BonusPointSettingForm, EmployeeBonusPointForm # ================Models for BonusPointSetting============== +@method_decorator(login_required, name="dispatch") +@method_decorator(permission_required("pms.view_bonuspointsetting"), name="dispatch") class BonusPointSettingSectionView(views.HorillaSectionView): """ BonusPointSetting SectionView @@ -29,6 +35,8 @@ class BonusPointSettingSectionView(views.HorillaSectionView): template_name = "bonus/bonus_point_setting_section.html" +@method_decorator(login_required, name="dispatch") +@method_decorator(permission_required("pms.view_bonuspointsetting"), name="dispatch") class BonusPointSettingNavView(views.HorillaNavView): """ BonusPointSetting nav view @@ -48,6 +56,8 @@ class BonusPointSettingNavView(views.HorillaNavView): search_swap_target = "#listContainer" +@method_decorator(login_required, name="dispatch") +@method_decorator(permission_required("pms.change_bonuspointsetting"), name="dispatch") class BonusPointSettingFormView(views.HorillaFormView): """ BonusPointSettingForm View @@ -90,6 +100,8 @@ class BonusPointSettingFormView(views.HorillaFormView): return super().form_valid(form) +@method_decorator(login_required, name="dispatch") +@method_decorator(permission_required("pms.view_bonuspointsetting"), name="dispatch") class BonusPointSettingListView(views.HorillaListView): """ BnusPointSetting list view @@ -99,30 +111,6 @@ class BonusPointSettingListView(views.HorillaListView): search_url = reverse_lazy("bonus-point-setting-list-view") filter_class = BonusPointSettingFilter action_method = "action_template" - # actions = [ - # { - # "action": "Edit", - # "icon": "create-outline", - # "attrs": """ - # class="oh-btn oh-btn--light-bkg w-100" - # hx-get="{edit_url}?instance_ids={ordered_ids}" - # hx-target="#genericModalBody" - # data-target="#genericModal" - # data-toggle="oh-modal-toggle" - # """, - # }, - # { - # "action": "Delete", - # "icon": "trash-outline", - # "attrs": """ - # class="oh-btn oh-btn--light-bkg w-100 tex-danger" - # onclick=" - # event.stopPropagation(); - # confirm('Do you want to delete the bonus point setting?','{delete_url}') - # " - # """, - # }, - # ] columns = [ ("Model", "get_model_display"), @@ -228,42 +216,31 @@ class EmployeeBonusPointListView(views.HorillaListView): BnusPoint list view """ + request = getattr(horilla_middlewares._thread_locals, "request", None) + model = models.EmployeeBonusPoint search_url = reverse_lazy("employee-bonus-point-list-view") filter_class = EmployeeBonusPointFilter - action_method = "action_template" + if is_reportingmanager(request): + action_method = "action_template" bulk_update_fields = [ "employee_id", "bonus_point", "based_on", ] - # actions = [ - # { - # "action": "Edit", - # "icon": "create-outline", - # "attrs": """ - # class="oh-btn oh-btn--light-bkg w-100" - # hx-get="{edit_url}?instance_ids={ordered_ids}" - # hx-target="#genericModalBody" - # data-target="#genericModal" - # data-toggle="oh-modal-toggle" - # """, - # }, - # { - # "action": "Delete", - # "icon": "trash-outline", - # "attrs": """ - # class="oh-btn oh-btn--light-bkg w-100 tex-danger" - # onclick=" - # event.stopPropagation(); - # confirm('Do you want to delete the automation?','{delete_url}') - # " - # """, - # }, - # ] columns = [ ("Employee", "employee_id"), ("Bonus Point", "bonus_point"), ("Based On", "based_on"), ] + + 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) diff --git a/pms/forms.py b/pms/forms.py index 6b55853f1..b3d067b52 100644 --- a/pms/forms.py +++ b/pms/forms.py @@ -1048,6 +1048,16 @@ class MeetingsForm(BaseForm): ids = self.data.getlist("employee_id") if ids: self.errors.pop("employee_id", None) + + if cleaned_data["answer_employees"] and not cleaned_data["question_template"]: + raise ValidationError( + { + "question_template": _( + "Question template is required when answer employees are choosed" + ) + } + ) + return cleaned_data def __init__(self, *args, **kwargs): @@ -1063,6 +1073,7 @@ class MeetingsForm(BaseForm): filter_class=EmployeeFilter, filter_instance_contex_name="f", filter_template_path="employee_filters.html", + form=self, ), label=_("Employees"), ) diff --git a/pms/templates/bonus/is_active_toggle.html b/pms/templates/bonus/is_active_toggle.html index 1a9febbe9..e83f848eb 100644 --- a/pms/templates/bonus/is_active_toggle.html +++ b/pms/templates/bonus/is_active_toggle.html @@ -2,8 +2,8 @@
{% if perms.pms.change_bonuspointsetting %} {% else %} diff --git a/pms/urls.py b/pms/urls.py index 8039b0c3a..326aba601 100644 --- a/pms/urls.py +++ b/pms/urls.py @@ -1,6 +1,7 @@ from django.urls import path from base.views import object_delete +from horilla_audit.methods import history_tracking from pms import cbvs from . import models, views @@ -417,11 +418,6 @@ urlpatterns = [ name="dashboard-feedback-answer", ), # ===========bonus point setting============ - # path( - # "view-bonus-setting", - # views.view_bonus_setting, - # name="view-bonus-setting", - # ), path( "bonus-point-setting/", cbvs.BonusPointSettingSectionView.as_view(), @@ -457,6 +453,11 @@ urlpatterns = [ views.bonus_setting_form_values, name="bonus-setting-form-values", ), + path( + "update-isactive-bonuspoint-setting/", + views.update_isactive_bonuspoint_setting, + name="update-isactive-bonuspoint-setting", + ), # ===========Employee bonus point============ path( "employee-bonus-point", @@ -488,4 +489,10 @@ urlpatterns = [ views.delete_employee_bonus_point, name="delete-employee-bonus-point", ), + path( + "history-tracking//", + history_tracking, + name="history-tracking", + kwargs={"model": models.Meetings, "decorators": ["login_required"]}, + ), ]