[UPDT] PAYROLL: Based on children allowance calculation
This commit is contained in:
@@ -360,6 +360,9 @@ def calculate_allowance(**kwargs):
|
||||
no_tax_allowances_amt.append(amount)
|
||||
|
||||
else:
|
||||
print("===========================")
|
||||
print(allowance.based_on)
|
||||
print()
|
||||
calculation_function = calculation_mapping.get(allowance.based_on)
|
||||
amount = calculation_function(
|
||||
**{
|
||||
@@ -972,6 +975,29 @@ def calculate_based_on_work_type(*_args, **kwargs):
|
||||
return amount
|
||||
|
||||
|
||||
def calculate_based_on_children(*_args, **kwargs):
|
||||
"""
|
||||
Calculates the amount of an allowance or deduction based on the attendance of an employee.
|
||||
|
||||
Args:
|
||||
employee (Employee): The employee for whom the attendance is being calculated.
|
||||
start_date (date): The start date of the attendance period.
|
||||
end_date (date): The end date of the attendance period.
|
||||
component (Allowance or Deduction): The allowance or deduction object.
|
||||
day_dict (dict): Dictionary containing working day details.
|
||||
|
||||
Returns:
|
||||
float: The calculated amount of the component based on the attendance.
|
||||
"""
|
||||
employee = kwargs["employee"]
|
||||
component = kwargs["component"]
|
||||
day_dict = kwargs["day_dict"]
|
||||
count = employee.children
|
||||
amount = count * component.per_children_fixed_amount
|
||||
amount = compute_limit(component, amount, day_dict)
|
||||
return amount
|
||||
|
||||
|
||||
calculation_mapping = {
|
||||
"basic_pay": calculate_based_on_basic_pay,
|
||||
"gross_pay": calculate_based_on_gross_pay,
|
||||
@@ -981,4 +1007,5 @@ calculation_mapping = {
|
||||
"shift_id": calculate_based_on_shift,
|
||||
"overtime": calculate_based_on_overtime,
|
||||
"work_type_id": calculate_based_on_work_type,
|
||||
"children": calculate_based_on_children,
|
||||
}
|
||||
|
||||
@@ -689,6 +689,7 @@ class Allowance(HorillaModel):
|
||||
("shift_id", _("Shift")),
|
||||
("overtime", _("Overtime")),
|
||||
("work_type_id", _("Work Type")),
|
||||
("children", _("Children")),
|
||||
]
|
||||
|
||||
if_condition_choice = [
|
||||
@@ -792,6 +793,14 @@ class Allowance(HorillaModel):
|
||||
validators=[min_zero],
|
||||
help_text=_("The attendance fixed amount for one validated attendance"),
|
||||
)
|
||||
# If based on children
|
||||
per_children_fixed_amount = models.FloatField(
|
||||
null=True,
|
||||
blank=True,
|
||||
default=0.00,
|
||||
validators=[min_zero],
|
||||
help_text=_("The fixed amount per children"),
|
||||
)
|
||||
# If based on shift
|
||||
shift_id = models.ForeignKey(
|
||||
EmployeeShift,
|
||||
@@ -966,7 +975,8 @@ class Allowance(HorillaModel):
|
||||
raise ValidationError(
|
||||
_("If based on is work type, then work type must be filled.")
|
||||
)
|
||||
|
||||
if self.based_on == "children" and not self.per_children_fixed_amount:
|
||||
raise ValidationError(_("The amount per children must be filled."))
|
||||
if self.is_fixed and self.amount < 0:
|
||||
raise ValidationError({"amount": _("Amount should be greater than zero.")})
|
||||
|
||||
|
||||
@@ -57,7 +57,24 @@ function conditionalVisibility() {
|
||||
"#id_per_attendance_fixed_amount, [for='id_per_attendance_fixed_amount']"
|
||||
).parent().hide();
|
||||
}
|
||||
|
||||
if (
|
||||
$("#id_based_on").val() == "children" &&
|
||||
!$("#id_is_fixed").is(":checked")
|
||||
) {
|
||||
$(
|
||||
"#id_per_children_fixed_amount, [for='id_per_children_fixed_amount']"
|
||||
).show();
|
||||
$(
|
||||
"#id_per_children_fixed_amount, [for='id_per_children_fixed_amount']"
|
||||
).parent().show();
|
||||
} else {
|
||||
$(
|
||||
"#id_per_children_fixed_amount, [for='id_per_children_fixed_amount']"
|
||||
).hide();
|
||||
$(
|
||||
"#id_per_children_fixed_amount, [for='id_per_children_fixed_amount']"
|
||||
).parent().hide();
|
||||
}
|
||||
if (
|
||||
$("#id_based_on").val() == "shift_id" &&
|
||||
!$("#id_is_fixed").is(":checked")
|
||||
|
||||
Reference in New Issue
Block a user