Search code examples
pythonopenerp-8odoo-8

Define Salary Rules that Depend on Previous Rules in Odoo


The Personal Income Tax of an employee is computed in bands having different percentage of the annual gross pay. The rate of tax for the first band (first 300,000.00) is 7%, 11% for the next band (next 300,000.00) and so on. Given an annual gross of 500,000.00 the total tax is (7% of 300,000.00 + 11% of 200,000.00). I have a rule with code TAXABLE_INCOME and wish to compute the Personal Income Tax. I need to define additional rules that depend on this rule.

The first rule condition type is range and depends on "rules.TAXABLE_INCOME" and has range 0.00 - 300,000.00 and the amount type is percentage and is based on "300000.00 if rules.TAXABLE_INCOME > 300000.00 else rules.TAXABLE_INCOME" and the percent is 7%.

Now the challenge is that when I try to compute a payslip I get an error that the range condition is wrong. What is the right way to define what the range condition/percentage value depend on? Do I need to assign to result as in the python code approach?


Solution

  • The salary bands can be summarized as a list [(LowerBound, UpperBound, PercentTax),]

    The rule for a given band depends on: result = TAXABLE_INCOME > LowerBound while the value can be computed using: result = ((UpperBound - LowerBound) if TAXABLE_INCOME > UpperBound else (TAXABLE_INCOME - LowerBound)) * PercentTax / 100

    The most important discovery was that whereas the sample code refers to rules.NET prepending rules. to the rule id is an error. Hence, instead of rules.TAXABLE_INCOME use TAXABLE_INCOME directly.