Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update_compensation on net_pay is giving error on generating payslip #576

Open
unreal0901 opened this issue Mar 10, 2025 · 1 comment
Open

Comments

@unreal0901
Copy link
Contributor

unreal0901 commented Mar 10, 2025

Can you check and verify as
when i create a update compensation on net pay for a specific employee.
It is throwing the following error when generating payslips:

Internal Server Error: /payroll/create-payslip
Traceback (most recent call last):
  File "/home/ec2-user/project/horilla/horilla/decorators.py", line 234, in wrapped_view
    func = view_func(request, *args, **kwargs)
  File "/home/ec2-user/project/horilla/horilla/decorators.py", line 41, in _function
    return function(request, *args, **kwargs)
  File "/home/ec2-user/project/horilla/payroll/views/component_views.py", line 909, in create_payslip
    calculate_employer_contribution(data)
  File "/home/ec2-user/project/horilla/payroll/methods/methods.py", line 560, in calculate_employer_contribution
    amount * object.employer_rate
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

This is the data am getting in save method of Deduction form creation:

json
{
  "csrfmiddlewaretoken": "kiroZ/2LaPFeQWv4tZSw7r1fK0bUIOZ1GgbnG6hzPEfb131C...",
  "title": "net_pay_compensation_Deductions",
  "one_time_date": "2025-03-10",
  "specific_employees": "6",
  "search": "",
  "is_pretax": "on",
  "field": "",
  "condition": "",
  "value": "",
  "update_compensation": "net_pay",
  "amount": "1000",
  "based_on": "",
  "rate": "0.0",
  "employer_rate": "0.0",
  "maximum_amount": "",
  "maximum_unit": "month_working_days",
  "if_choice": "basic_pay",
  "if_condition": "gt",
  "if_amount": "0.0",
  "start_range": "",
  "end_range": ""
}

As you can see the based on will be saved as None in the database, but now in calculate employee contribution funciton , its throwing that error.

def calculate_employer_contribution(data):
    """
    This method is used to calculate the employer contribution
    """
    pay_head_data = data["pay_data"]
    deductions_to_process = [
        pay_head_data.get("pretax_deductions"),
        pay_head_data.get("post_tax_deductions"),
        pay_head_data.get("tax_deductions"),
        pay_head_data.get("net_deductions"),
    ]

    for deductions in deductions_to_process:
        if deductions:
            for deduction in deductions:
                if (
                    deduction.get("deduction_id")
                    and deduction.get("employer_contribution_rate", 0) > 0
                ):
                    object = Deduction.objects.filter(
                        id=deduction.get("deduction_id")
                    ).first()
                    if object:
                        amount = pay_head_data.get(object.based_on)
                        employer_contribution_amount = (
                            amount * object.employer_rate
                        ) / 100
                        deduction["based_on"] = object.based_on
                        deduction["employer_contribution_amount"] = (
                            employer_contribution_amount
                        )
    return data

Also i think employer_contribution for other type of taxes is not calculating correctly.

@horilla-opensource
Copy link
Owner

Hi @unreal0901 ,

Thanks for reporting this issue!

It looks like the based_on field is getting saved as None in the database, which is causing the TypeError in the calculate_employer_contribution function when trying to multiply it with employer_rate.

We will check and verify the issue, including the calculation of employer contributions for other tax types. We'll update you once we have a fix.

Best Regards,
Team Horilla

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants