Odoo Help


How to write a function to calculate a percentage in openerp?

on 3/1/13, 8:36 AM 2,084 views

Hello all, please I have a field called annual_salary and i want to calculate the percentage increase in that field and display the result in another filed called annual_increase. How do I achieve it in OpenERP?


I assume you have the annual salary of the previous year available, am I right? In this case, where do you have it?

on 3/1/13, 8:55 AM

Yes i have it in another field called previous_annual_salary.

on 3/1/13, 9:45 AM

Thanks for your help but the issue is, I have a field called previous_annual_salary and and a field called new_annual salary. but the new_annual salary must not be greater that 25% of previous_annual_salary. The function should be able to tell you if the new_annual_salary you imputed is greater than 25%. Thanks

on 3/1/13, 11:17 AM



| 6 5 7
Buenos Aires, Argentina
Karma will give me a place in heaven!
On 3/1/13, 10:08 AM

You should add a constraint in the definition of your model, like this:

def _check_annual_increase(self, cr, uid, ids,context=None):
    delta_salary = obj.previous_annual_salary and\
                        obj.annual_salary / obj.previous_annual_salary
    return (delta_salary < 1,25) 

_columns = { 
    annual_salary : ...
    previous_annual_salary : ...

_constraints = [
    (_check_annual_increase, ('Error! Annual increase can not exceed 25%'),

If none of your salary fields is of type float you need to cast at least one of the before doing the division in _check_annual_increase.

Hope now it solves the issue!

I will try it and get back to you. Thanks for your help!

on 3/1/13, 11:55 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/1/13, 8:36 AM
Seen: 2084 times
Last updated: 3/16/15, 8:10 AM