Small Feature Request on Income Tax Calculation

Hello community!

The current setup for Income Tax calculation is not quite flexible as I expected or rather, doesn’t work for my use case. Here is my situation:

Where we’re considering adopting ERPNext, Income Tax is calculated as demonstrated in the image below:

With the current setup. I can add the ranges and add the % percentage deductions (inverted). E.g In the given example in the image above, I’d subtract 80%.

But as you can see, the calculation does not end there, there still needs to be deducted another amount from the result of the first deduction.

My request is if there could be a way to make the final amount on each taxable_salary_slab dependant on a formula as we do with Salary Components.

  1. Check field for “amount_dependant_on_formula”
  2. Have “amount” or “taxable_earnings” available in the context for use in the formula

With this, I’d then go on to adding a formula such as:

(taxable_earnings - (0.8 * taxable_earnings)) - 4500  # <- Additional amount/other expressions.

This is the problem I’m currently faced with, there is no way to add a formula. Now, I’m still a newbie to ERPNext and Frappe, but not to Python. I have seen how flexible ERPNext is, so if someone can point me to where I can add some tweaks to achieve this desired result, whether by custom scrips, or server scripts, or any other way possible.

Any advice/suggestion is welcome.

Regards
Redren.

Hi there,

Tax slabs are used to estimate withholding on deductions that are assessed across multiple pay periods (i.e., most typically annual income tax and monthly/weekly pay). If income tax is being assessed per pay period, you should be using Salary Component formulas to calculate it. With Salary Components, you can have as many stages or nested levels as you’d like.

2 Likes

Thanks for the respose Peter. I’ve been thinking about implementing this as Salary Components as you suggest. So say I was to calculate the Tax Component based on for example:

taxable_amount =

  • Gross Salary - Exempt Income (from other components)
  • Less certain deductions (from other components)

Then apply the tax based on ranges, probably via nested ifs to avoid a handful of components. Is this possible? To make deduction after making other deductions as my example scenario.

Yes, it’s definitely possible. The calculation formulas need to be limited to a single eval statement, but you nest a bunch of conditional operators in there if you need to. It works but can get a bit messy. Alternately, you can use statistical components, which are calculated like any other component but don’t show up by themselves on a pay slip. For your case, to get income tax, you might define each bracket individually as statistical components b0b5, each with its own condition, and then create a single income tax component (non-statistical) that is just b0 + b1 + b2 + b3 + b4 + b5.

3 Likes

Once again, thanks for the assistance, much appreciated. Let me get onto it. Will bring back an update on my findings.

Cheers

Thanks a lot Peter. Your suggestion worked like charm!

1 Like

Hello, everyone I have successfully, made formulas and I have succeeded in generating payroll, can some help how I can put the amount and percentage in tax slabs? as erpnext just takes the percentage

Taxable Income Income Tax Rate in Pakistan
Where taxable income does not exceed Rs600,000 The tax rate is zero
Where taxable income exceeds Rs. 600,000 but does not exceed Rs. 1,200,000 2.5 per cent of the amount exceeding Rs 600,000
Where taxable income exceed Rs1,200,000 but does not exceed Rs2,400,000 Rs15,000 + 12.5 per cent of the amount exceeding Rs1,200,000
If taxable income exceeds Rs2,400,000 but does not exceed Rs3,600,000 Rs165,000 + 20% of the amount exceeding Rs2,400,000
Where taxable income exceeds Rs3,600,000 but does not exceed Rs6,000,000 Rs405,000 + 25 per cent of the amount exceeding Rs3,600,000
If taxable income exceeds Rs6,000,000 but does not exceed Rs12,000,000 Rs1,005,000 + 32.5 per cent of the amount exceeding Rs6,000,000
Where taxable income exceeds Rs12,000,000 Rs2,955,000 + 35 per cent of the amount exceeding Rs12,000,000

how we can do this?

hi @Muzzammil_Hussain i need to set the same limitation that tax should be only applicable if the CTC is above 7.5lakhs how its possible

Yes, your request for formula-based income tax slab calculation in ERPNext is both valid and achievable through customization—even though ERPNext’s default tax slab setup is a bit rigid.

Here’s how you can address it:

What’s Missing in Current ERPNext Income Tax Setup

The current tax slab setup in ERPNext supports flat rate deductions per range, but it doesn’t allow chained or compound calculations (like applying a percentage, then subtracting a fixed amount).

How You Can Solve This

Option 1: Use Server Scripts (Recommended for Advanced Logic)

ERPNext (v13+) supports Server Scripts—you can write custom Python logic that executes during payroll processing.

  1. Go to Custom Script > Server Script

  2. Type: “Payroll Entry”

  3. Trigger: “Before Submit”

Script example:

for ss in doc.salary_slips:

taxable = ss.gross_pay

tax = (taxable - (0.8 * taxable)) - 4500

ss.append(“deductions”, {

“salary_component”: “Income Tax”,

“amount”: tax

})

You can also use a custom field to define slabs and formulas dynamically.

Option 2: Custom Salary Component with Formula

You can create a Salary Component called “Income Tax (Custom)”:

  • Set “Condition” to base > 0

Set “Amount based on formula” to:

(base - (0.8 * base)) - 4500

But ERPNext formula builder is limited—you won’t have access to slab-based branching here unless you hardcode ranges.

Option 3: Custom Python App (For Full Flexibility)

If you’re comfortable with Python and Frappe, you can override the calculate_income_tax_for_employee() method in the Payroll Controller, or hook into salary_slip.py for full control.

Final Suggestion

For most use cases, Server Scripts offer the right balance of power and maintainability—no need to build or deploy a custom app.