[ADD] REPORT: Add reporting module for Horilla (#750)

This commit is contained in:
Horilla
2025-05-19 16:51:04 +05:30
committed by GitHub
parent caf8e5a3d4
commit 0b327c4923
35 changed files with 5073 additions and 0 deletions

View File

@@ -279,6 +279,22 @@ class PayslipFilter(FilterSet):
month = django_filters.CharFilter(field_name="start_date", lookup_expr="month")
year = django_filters.CharFilter(field_name="start_date", lookup_expr="year")
allowance_title = django_filters.CharFilter(
method="filter_by_allowance_title", label="Allowance Title"
)
allowance_amount_gte = django_filters.NumberFilter(
method="filter_by_allowance_amount_gte"
)
allowance_amount_lte = django_filters.NumberFilter(
method="filter_by_allowance_amount_lte"
)
deduction_amount_gte = django_filters.NumberFilter(
method="filter_by_deduction_amount_gte"
)
deduction_amount_lte = django_filters.NumberFilter(
method="filter_by_deduction_amount_lte"
)
class Meta:
"""
Meta class to add additional options
@@ -298,8 +314,82 @@ class PayslipFilter(FilterSet):
"net_pay__lte",
"net_pay__gte",
"sent_to_employee",
"allowance_amount_gte",
"allowance_amount_lte",
"deduction_amount_gte",
"deduction_amount_lte",
]
def filter_by_allowance_amount_gte(self, queryset, name, value):
return queryset.filter(
id__in=[
p.id
for p in queryset
if any(
float(allowance.get("amount", 0)) >= float(value)
for allowance in (p.pay_head_data or {}).get("allowances", [])
)
]
)
def filter_by_allowance_amount_lte(self, queryset, name, value):
return queryset.filter(
id__in=[
p.id
for p in queryset
if all(
float(allowance.get("amount", 0)) <= float(value)
for allowance in (p.pay_head_data or {}).get("allowances", [])
)
]
)
def filter_by_deduction_amount_lte(self, queryset, name, value):
value = float(value)
deduction_keys = [
"pretax_deductions",
"gross_pay_deductions",
"basic_pay_deductions",
"post_tax_deductions",
"tax_deductions",
"net_deductions",
]
return queryset.filter(
id__in=[
p.id
for p in queryset
if all(
float(d.get("amount", 0)) <= value
for key in deduction_keys
for d in (p.pay_head_data or {}).get(key, [])
)
]
)
def filter_by_deduction_amount_gte(self, queryset, name, value):
value = float(value)
deduction_keys = [
"pretax_deductions",
"gross_pay_deductions",
"basic_pay_deductions",
"post_tax_deductions",
"tax_deductions",
"net_deductions",
]
return queryset.filter(
id__in=[
p.id
for p in queryset
if any(
float(d.get("amount", 0)) >= value
for key in deduction_keys
for d in (p.pay_head_data or {}).get(key, [])
)
]
)
def __init__(self, data=None, queryset=None, *, request=None, prefix=None):
super().__init__(data=data, queryset=queryset, request=request, prefix=prefix)
for field in self.form.fields.keys():