pythonodooodoo-9

Odoo 9: Unable to use math functions in Salary Rule


First of all, I'm a Python beginner and learning to use Odoo now. I have been trying roundup the result using Python Code in Salary Rule.

Payroll\Configuration\Salary Rules

I found out there is a math function of math.ceil() to roundup the result. So I code the code below:

import math
result = math.ceil(categories.BASIC * 0.05)

But I couldn't get it to work. Did I import the math library correctly?


Solution

  • Unfortunately you can't import python modules there, an alternative is to use the built-in round function in python

    result = round((categories.BASIC * 0.05) + 0.5)
    

    Here I just specified to round the result to 2 digits, but it can be anything you want