From 633beb29ba766a2eca06c1e26b46125ac1b968aa Mon Sep 17 00:00:00 2001 From: Horilla Date: Thu, 1 Feb 2024 13:09:43 +0530 Subject: [PATCH] [ADD] EMPLOYEE: Badge id setup in settings --- base/context_processors.py | 15 +++ base/templates/base/general_settings.html | 1 + employee/urls.py | 110 +++++++++++++++++----- employee/views.py | 45 +++++++-- horilla/horilla_context_processors.py | 5 + 5 files changed, 146 insertions(+), 30 deletions(-) diff --git a/base/context_processors.py b/base/context_processors.py index aa7d14490..4225e29e6 100644 --- a/base/context_processors.py +++ b/base/context_processors.py @@ -8,6 +8,7 @@ from django.http import HttpResponse from attendance.models import AttendanceGeneralSetting from base.models import Company from base.urls import urlpatterns +from employee.models import EmployeeGeneralSetting from offboarding.models import OffboardingGeneralSetting from payroll.models.models import PayrollGeneralSetting from recruitment.models import RecruitmentGeneralSetting @@ -149,3 +150,17 @@ def check_candidate_self_tracking_rating(request): if first: rating_option = first.show_overall_rating return {"check_candidate_self_tracking_rating": rating_option} + + + +def get_intial_prefix(request): + """ + This method is used to get the initial prefexi + """ + settings = EmployeeGeneralSetting.objects.first() + instance_id = None + prefix = "PEP" + if settings: + instance_id = settings.id + prefix = settings.badge_id_prefix + return {"get_intial_prefix":prefix,"prefix_instance_id":instance_id} \ No newline at end of file diff --git a/base/templates/base/general_settings.html b/base/templates/base/general_settings.html index 3a839bc8a..f6d8a2c0f 100644 --- a/base/templates/base/general_settings.html +++ b/base/templates/base/general_settings.html @@ -5,6 +5,7 @@ {% include "offboarding/settings/settings.html" %} {% include "attendance/settings/settings.html" %} {% include "payroll/settings/settings.html" %} +{% include "settings/settings.html" %} {% include "announcement/expiry_day.html" %} {% include "settings/encashment_settings.html" %} diff --git a/employee/urls.py b/employee/urls.py index eaafab4aa..72d046300 100644 --- a/employee/urls.py +++ b/employee/urls.py @@ -214,8 +214,12 @@ urlpatterns = [ kwargs={"model": Employee}, ), path("document-tab/", views.document_tab, name="document-tab"), - path("bonus-points-tab/", views.bonus_points_tab, name="bonus-points-tab"), - path("add-bonus-points/", views.add_bonus_points, name="add-bonus-points"), + path( + "bonus-points-tab/", views.bonus_points_tab, name="bonus-points-tab" + ), + path( + "add-bonus-points/", views.add_bonus_points, name="add-bonus-points" + ), path("redeem-points/", views.redeem_points, name="redeem-points"), path("employee-select/", views.employee_select, name="employee-select"), path( @@ -244,22 +248,58 @@ urlpatterns = [ path("search-policies", policies.search_policies, name="search-policies"), path("create-policy", policies.create_policy, name="create-policy"), path("view-policy", policies.view_policy, name="view-policy"), - path("add-attachment-policy", policies.add_attachment, name="add-attachment-policy"), - path("remove-attachment-policy", policies.remove_attachment, name="remove-attachment-policy"), - path("get-attachments-policy", policies.get_attachments, name="get-attachments-policy"), + path( + "add-attachment-policy", policies.add_attachment, name="add-attachment-policy" + ), + path( + "remove-attachment-policy", + policies.remove_attachment, + name="remove-attachment-policy", + ), + path( + "get-attachments-policy", + policies.get_attachments, + name="get-attachments-policy", + ), path("file-upload/", views.file_upload, name="file-upload"), path("view-file/", views.view_file, name="view-file"), path("document-create", views.document_create, name="document-create"), path("document-create/", views.document_create, name="document-create"), - path("update-document-title/", views.update_document_title, name="update-document-title"), + path( + "update-document-title/", + views.update_document_title, + name="update-document-title", + ), path("document-approve/", views.document_approve, name="document-approve"), - path("document-bulk-approve", views.document_bulk_approve, name="document-bulk-approve"), - path("document-bulk-reject", views.document_bulk_reject, name="document-bulk-reject"), + path( + "document-bulk-approve", + views.document_bulk_approve, + name="document-bulk-approve", + ), + path( + "document-bulk-reject", views.document_bulk_reject, name="document-bulk-reject" + ), path("document-reject/", views.document_reject, name="document-reject"), - path("document-request-view/", views.document_request_view, name="document-request-view"), - path("document-request-filter-view", views.document_filter_view, name="document-request-filter-view"), - path("document-request-create", views.document_request_create, name="document-request-create"), - path("document-request-update/", views.document_request_update, name="document-request-update"), + path( + "document-request-view/", + views.document_request_view, + name="document-request-view", + ), + path( + "document-request-filter-view", + views.document_filter_view, + name="document-request-filter-view", + ), + path( + "document-request-create", + views.document_request_create, + name="document-request-create", + ), + path( + "document-request-update/", + views.document_request_update, + name="document-request-update", + ), path( "document-request-kwargs={'model':Employee}delete//", object_delete, @@ -272,16 +312,40 @@ urlpatterns = [ name="document-delete", ), path("organisation-chart/", views.organisation_chart, name="organisation-chart"), - - path("delete-policies",policies.delete_policies,name="delete-policies"), - - path("disciplinary-actions/", policies.disciplinary_actions, name="disciplinary-actions"), + path("delete-policies", policies.delete_policies, name="delete-policies"), + path( + "disciplinary-actions/", + policies.disciplinary_actions, + name="disciplinary-actions", + ), path("create-actions", policies.create_actions, name="create-actions"), - path("update-actions//", policies.update_actions, name="update-actions"), - path("delete-actions//",policies.delete_actions, name="delete-actions"), - path("action-type-details",policies.action_type_details,name="action-type-details",), - path("disciplinary-filter-view", policies.disciplinary_filter_view, name="disciplinary-filter-view"), - path("search-disciplinary", policies.search_disciplinary, name="search-disciplinary"), - path("encashment-condition-create", views.encashment_condition_create, name="encashment-condition-create"), - + path( + "update-actions//", + policies.update_actions, + name="update-actions", + ), + path( + "delete-actions//", + policies.delete_actions, + name="delete-actions", + ), + path( + "action-type-details", + policies.action_type_details, + name="action-type-details", + ), + path( + "disciplinary-filter-view", + policies.disciplinary_filter_view, + name="disciplinary-filter-view", + ), + path( + "search-disciplinary", policies.search_disciplinary, name="search-disciplinary" + ), + path( + "encashment-condition-create", + views.encashment_condition_create, + name="encashment-condition-create", + ), + path("initial-prefix",views.initial_prefix,name="initial-prefix") ] diff --git a/employee/views.py b/employee/views.py index 554172bee..03d9092ce 100755 --- a/employee/views.py +++ b/employee/views.py @@ -91,13 +91,20 @@ from horilla_documents.forms import ( from employee.models import ( BonusPoint, Employee, + EmployeeGeneralSetting, EmployeeNote, EmployeeWorkInformation, EmployeeBankDetails, ) from payroll.forms.forms import EncashmentGeneralSettingsForm from payroll.methods.payslip_calc import dynamic_attr -from payroll.models.models import Allowance, Contract, Deduction, EncashmentGeneralSettings, Reimbursement +from payroll.models.models import ( + Allowance, + Contract, + Deduction, + EncashmentGeneralSettings, + Reimbursement, +) from pms.models import Feedback from recruitment.models import Candidate from horilla_documents.models import Document, DocumentRequest @@ -2746,20 +2753,24 @@ def redeem_points(request, emp_id): """ user = Employee.objects.get(id=emp_id) form = BonusPointRedeemForm() - amount_for_bonus_point = EncashmentGeneralSettings.objects.first().bonus_amount if EncashmentGeneralSettings.objects.first() else 1 + amount_for_bonus_point = ( + EncashmentGeneralSettings.objects.first().bonus_amount + if EncashmentGeneralSettings.objects.first() + else 1 + ) if request.method == "POST": form = BonusPointRedeemForm(request.POST) if form.is_valid(): form.save(commit=False) points = form.cleaned_data["points"] amount = amount_for_bonus_point * points - + reimbursement = Reimbursement.objects.create( title=f"Bonus point Redeem for {user}", type="bonus_encashment", employee_id=user, bonus_to_encash=points, - amount = amount, + amount=amount, description=f"{user} want to redeem {points} points", allowance_on=date.today(), ) @@ -2866,10 +2877,30 @@ def encashment_condition_create(request): instance = EncashmentGeneralSettings.objects.first() encashment_form = EncashmentGeneralSettingsForm(instance=instance) if request.method == "POST": - encashment_form = EncashmentGeneralSettingsForm(request.POST,instance=instance) + encashment_form = EncashmentGeneralSettingsForm(request.POST, instance=instance) if encashment_form.is_valid(): encashment_form.save() messages.success(request, _("Settings updated.")) return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) - - return render(request, "settings/encashment_settings.html", {"encashment_form":encashment_form,}) + + return render( + request, + "settings/encashment_settings.html", + { + "encashment_form": encashment_form, + }, + ) + + +@login_required +@permission_required("employee.add_employeegeneralsetting") +def initial_prefix(request): + """ + This method is used to set initial prefix + """ + instance = EmployeeGeneralSetting.objects.first() + instance = instance if instance else EmployeeGeneralSetting() + instance.badge_id_prefix = request.POST["initial_prefix"] + instance.save() + messages.success(request,"Initial prefix update") + return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) diff --git a/horilla/horilla_context_processors.py b/horilla/horilla_context_processors.py index 697c8c6e5..918d7cd53 100644 --- a/horilla/horilla_context_processors.py +++ b/horilla/horilla_context_processors.py @@ -23,3 +23,8 @@ TEMPLATES[0]["OPTIONS"]["context_processors"].append( TEMPLATES[0]["OPTIONS"]["context_processors"].append( "base.context_processors.check_candidate_self_tracking_rating", ) + +TEMPLATES[0]["OPTIONS"]["context_processors"].append( + "base.context_processors.get_intial_prefix", +) +