Which syntax should I follow while writing a condition/formula for Salary Component on the ErpNext interface on a live/testing system?
We have multiple nested conditionals but it is not clear where to code these. Turkey has a very very complex Payroll structure and is additionally intrigued with the addition of incentives. I am mostly stuck with date comparison and differences, calculating ages, incentive start/end dates, etc. which are all custom fields.
Any guiding light will help. Thank you.
Hi! Learning happens when folks share their work and experiments Salary Structure Multiple Condition on Earning
1 Like
Maybe get specific and offer a challenge - that may spur interest and response.
Give folks your ‘hardest’ case examples, one or two that work and that don’t.
“which are all custom fields”
Is this the basic problem or what?
You are right on that sense.
Some components of the incentive we are implementing depends on the following:
- number of months last worked date before joining. We defined a custom field for employee which is the last working day before joining. We need to determine if this is 6 months before joining or not.
- age of the employee. That can be determined from the date_of_birth intrinsic employee field but to calculate the age in salary component is a bit tricky. There are different incentive lengths for different age groups.
- number of months that the incentive is applied. The number of months calculated must be added to the date_of_joining and yet again date operations need to be known. Which language shall we use? Python?
CORRECT MULTICONDITION IN SALARY COMPONENT ENTERED IN FORMULA SECTION
SINGLE LINE ONLY:
400 if base>19749.99 else int((base+500-2249.99)/500)*10+40 if base>2249.99 else 40
or
MULTIPLE LINES:
400 if base>19749.99 else
int((base+500-2249.99)/500)*10+40 if base>2249.99 else
40
VERY IMPORTANT NOTES:
- In multiple lines, there is space character after else. This is the error that took me days to check.
- There is no IF on the last line.
- Multiple conditions does not work on the Conditions box, I don’t actually use it anymore. I put everything in the Formula box.
The image shows the correct way of doing this and it’s working perfectly for me. The example is for the Philippines, where I simplified a very long table to a 3-line formula.
1 Like
…and how is that related?
Can I call an API to get a calculated value instead of writing the script?
since there are limitations in writing formula/condition, such as I cannot apply a condition based on another doctype and to achieve that can I write an API in which I will get Employee-ID and will calculate value considering all the conditions?
So the idea is that I want to handle all the conditions within the API instead of the formula and simply call that API within the formula/condition.
Perhaps you can create the salary component with a blank value, then use client script with a button that runs a function to populate the value. Even without a button
you should be able to run the code if you can gather the logic based on what’s
currently available.
1 Like