This question has been flagged
1 Reply
5380 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?

Thanks.

Avatar
Discard

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

Author

Yes i have it in another field called previous_annual_salary.

Author

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

Best Answer

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!

Avatar
Discard
Author

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