[ADD] EMPLOYEE: Bonus feature for employees
This commit is contained in:
@@ -859,7 +859,9 @@ def create_initial_stage(sender, instance, created, **kwargs):
|
||||
penalty.amount = instance.penalty_amount
|
||||
penalty.only_show_under_employee = True
|
||||
penalty.save()
|
||||
penalty.include_active_employees = False
|
||||
penalty.specific_employees.add(instance.employee_id)
|
||||
penalty.save()
|
||||
|
||||
if instance.leave_type_id and instance.minus_leaves:
|
||||
available = instance.employee_id.available_leave.filter(
|
||||
@@ -869,9 +871,6 @@ def create_initial_stage(sender, instance, created, **kwargs):
|
||||
if not instance.deduct_from_carry_forward:
|
||||
available.available_days = max(0, (available.available_days - unit))
|
||||
else:
|
||||
print("=================")
|
||||
print(available.carryforward_days)
|
||||
print(available.carryforward_days-unit)
|
||||
available.carryforward_days = max(
|
||||
0, (available.carryforward_days - unit)
|
||||
)
|
||||
|
||||
@@ -2,18 +2,25 @@
|
||||
{% load static %}
|
||||
{% load basefilters %}
|
||||
{% load attendancefilters %}
|
||||
<div class="oh-wrapper mt-4">
|
||||
<div class="oh-wrapper mt-4" id="AllowanceAndDeduction">
|
||||
<div class="oh-tabs">
|
||||
<ul class="oh-tabs__tablist">
|
||||
<li class="oh-tabs__tab oh-tabs__tab--active" data-target="#allowance_tab">
|
||||
<li class="oh-tabs__tab oh-tabs__tab--active d-flex justify-content-between" data-target="#allowance_tab">
|
||||
<div>
|
||||
<img
|
||||
<div>
|
||||
<img
|
||||
src="{% static 'images/ui/allowance_icon.png' %}"
|
||||
alt=""
|
||||
style="width: 25px; height: 25px; margin-right: 3px"
|
||||
/>
|
||||
{% trans "Allowances" %}
|
||||
</div>
|
||||
</div>
|
||||
{% if perms.payroll.add_allowance %}
|
||||
<button title="Add Bonus" class="oh-btn oh-btn--secondary-outline oh-stop-prop oh-accordion-meta__btn p-2" title="Add" hx-get="{% url "add-bonus" %}?employee_id={{employee.id}}" hx-target="#addBonusModalBody" data-target="#addBonusModal" data-toggle="oh-modal-toggle">
|
||||
<ion-icon class="md hydrated" name="add-outline" role="img" aria-label="add outline"></ion-icon>
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
</li>
|
||||
<li class="oh-tabs__tab" data-target="#deduction_tab">
|
||||
@@ -239,6 +246,16 @@
|
||||
<div class="oh-modal" id="AllowanceModal" role="dialog" aria-labelledby="AllowanceModal" aria-hidden="true">
|
||||
<div class="oh-modal__dialog oh-modal__dialog-relative" style="max-width: 550px" id="OneAllowanceTarget"></div>
|
||||
</div>
|
||||
|
||||
<div class="oh-modal" id="addBonusModal" role="dialog" aria-hidden="true">
|
||||
<div class="oh-modal__dialog">
|
||||
<div class="oh-modal__dialog-header">
|
||||
<button type="button" class="oh-modal__close" aria-label="Close"><ion-icon name="close-outline"></ion-icon></button>
|
||||
</div>
|
||||
|
||||
<div class="oh-modal__dialog-body" id="addBonusModalBody"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="oh-modal" id="DeductionModal" role="dialog" aria-labelledby="DeductionModal" aria-hidden="true">
|
||||
<div class="oh-modal__dialog oh-modal__dialog-relative" style="max-width: 600px" id="OneDeductionTarget"></div>
|
||||
</div>
|
||||
@@ -261,4 +278,8 @@
|
||||
$(newActiveTab).toggleClass("oh-tabs__content--active");
|
||||
});
|
||||
});
|
||||
let activeTabs = $("#AllowanceAndDeduction .oh-tabs__tab--active").length
|
||||
if(!activeTabs){
|
||||
$("#AllowanceAndDeduction .oh-tabs__tab").first().toggleClass("oh-tabs__tab--active")
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -444,6 +444,7 @@ def allowances_deductions_tab(request, emp_id):
|
||||
"active_contracts": active_contracts,
|
||||
"allowances": employee_allowances if employee_allowances else None,
|
||||
"deductions": employee_deductions if employee_deductions else None,
|
||||
"employee":employee,
|
||||
}
|
||||
return render(request, "tabs/allowance_deduction-tab.html", context=context)
|
||||
|
||||
|
||||
@@ -10,12 +10,12 @@ from django.template.loader import render_to_string
|
||||
from horilla_widgets.forms import HorillaForm
|
||||
from horilla_widgets.widgets.horilla_multi_select_field import HorillaMultiSelectField
|
||||
from horilla_widgets.widgets.select_widgets import HorillaMultiSelectWidget
|
||||
from base.forms import ModelForm
|
||||
from base.forms import Form, ModelForm
|
||||
from employee.models import Employee
|
||||
from employee.filters import EmployeeFilter
|
||||
from payroll.models import tax_models as models
|
||||
from payroll.widgets import component_widgets as widget
|
||||
from payroll.models.models import Contract
|
||||
from payroll.models.models import Allowance, Contract
|
||||
import payroll.models.models
|
||||
from base.methods import reload_queryset
|
||||
|
||||
@@ -309,3 +309,40 @@ class ContractExportFieldForm(forms.Form):
|
||||
"contract_status",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
class BonusForm(Form):
|
||||
"""
|
||||
Bonus Creating Form
|
||||
"""
|
||||
title = forms.CharField(max_length=100)
|
||||
date = forms.DateField(widget=forms.DateInput())
|
||||
employee_id = forms.IntegerField(label="Employee",widget=forms.HiddenInput())
|
||||
amount = forms.DecimalField(label="Amount")
|
||||
|
||||
def save(self, commit=True):
|
||||
title = self.cleaned_data["title"]
|
||||
date = self.cleaned_data["date"]
|
||||
employee_id = self.cleaned_data["employee_id"]
|
||||
amount = self.cleaned_data["amount"]
|
||||
|
||||
bonus = Allowance()
|
||||
bonus.title = title
|
||||
bonus.one_time_date = date
|
||||
bonus.only_show_under_employee = True
|
||||
bonus.amount = amount
|
||||
bonus.is_fixed = True
|
||||
bonus.save()
|
||||
bonus.include_active_employees = False
|
||||
bonus.specific_employees.set([employee_id])
|
||||
bonus.save()
|
||||
|
||||
return bonus
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
for field_name, field in self.fields.items():
|
||||
field.widget.attrs.update({"class": "oh-input w-100"})
|
||||
self.fields["date"].widget = forms.DateInput(
|
||||
attrs={"type": "date", "class": "oh-input w-100"}
|
||||
)
|
||||
|
||||
6
payroll/templates/payroll/bonus/form.html
Normal file
6
payroll/templates/payroll/bonus/form.html
Normal file
@@ -0,0 +1,6 @@
|
||||
<form hx-post="{% url 'add-bonus' %}?employee_id={{employee_id}}" hx-target="#addBonusModalBody">
|
||||
{{ form }}
|
||||
<div class="d-flex flex-row-reverse">
|
||||
<button type="submit" class="oh-btn oh-btn--secondary mt-2 mr-0 pl-4 pr-5 oh-btn--w-100-resp">Add</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -70,6 +70,7 @@ urlpatterns = [
|
||||
component_views.hx_create_allowance,
|
||||
name="hx-create-allowance",
|
||||
),
|
||||
path("send-slip",component_views.send_slip,name="send-slip")
|
||||
path("send-slip",component_views.send_slip,name="send-slip"),
|
||||
path("add-bonus/",component_views.add_bonus,name="add-bonus")
|
||||
|
||||
]
|
||||
|
||||
@@ -223,7 +223,9 @@ def view_allowance(request):
|
||||
"""
|
||||
This method is used render template to view all the allowance instances
|
||||
"""
|
||||
allowances = payroll.models.models.Allowance.objects.exclude(only_show_under_employee=True)
|
||||
allowances = payroll.models.models.Allowance.objects.exclude(
|
||||
only_show_under_employee=True
|
||||
)
|
||||
allowance_filter = AllowanceFilter(request.GET)
|
||||
allowances = paginator_qry(allowances, request.GET.get("page"))
|
||||
allowance_ids = json.dumps([instance.id for instance in allowances.object_list])
|
||||
@@ -354,7 +356,9 @@ def view_deduction(request):
|
||||
This method is used render template to view all the deduction instances
|
||||
"""
|
||||
|
||||
deductions = payroll.models.models.Deduction.objects.exclude(only_show_under_employee=True)
|
||||
deductions = payroll.models.models.Deduction.objects.exclude(
|
||||
only_show_under_employee=True
|
||||
)
|
||||
deduction_filter = DeductionFilter(request.GET)
|
||||
deductions = paginator_qry(deductions, request.GET.get("page"))
|
||||
deduction_ids = json.dumps([instance.id for instance in deductions.object_list])
|
||||
@@ -840,3 +844,20 @@ def send_slip(request):
|
||||
mail_thread.start()
|
||||
messages.info(request, "Mail processing")
|
||||
return redirect(view_payslip)
|
||||
|
||||
|
||||
@login_required
|
||||
@permission_required("payroll.add_allowance")
|
||||
def add_bonus(request):
|
||||
print("========================================")
|
||||
print(request.GET)
|
||||
print("========================================")
|
||||
employee_id = request.GET["employee_id"]
|
||||
form = forms.BonusForm(initial={"employee_id": employee_id})
|
||||
if request.method == "POST":
|
||||
form = forms.BonusForm(request.POST, initial={"employee_id": employee_id})
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(request, "Bonus Added")
|
||||
return HttpResponse("<script>window.location.reload()</script>")
|
||||
return render(request, "payroll/bonus/form.html", {"form": form,"employee_id":employee_id})
|
||||
|
||||
Reference in New Issue
Block a user