Odoo Help


string to integer in salary rule python

on 7/3/13, 11:40 AM 3,292 views

In the object hr.salary.rule in field amount_python_compute I need to transform a string into a integer.

I tried

import ast 

but none of these works.

Did you make a custom module, do you change it in the XML, But most important, what is the errormessage(s) and what is in the logfile?

on 7/3/13, 5:18 PM

it just throw the exception of file hr_payroll.py of the funcion compute_rule raise osv.except_osv(_('Error!'), _('Wrong python code defined for salary rule %s (%s).')% (rule.name, rule.code))

on 7/3/13, 5:44 PM

I just found a workaround

on 7/3/13, 5:58 PM
On 7/3/13, 6:03 PM

you can modify the code in server\openerp\tools\safe_eval.py in function safe_eval in the dictionary variable __builtins__ add:


this is the dictionary __builtins__ to note the available functions plus int, those are the funtions that you can use in any module that use safe_eval

__builtins__ = {
            '__import__': _import,
            'True': True,
            'False': False,
            'None': None,
            'str': str,
            'globals': locals,
            'locals': locals,
            'bool': bool,
            'dict': dict,
            'list': list,
            'tuple': tuple,
            'map': map,
            'abs': abs,
            'min': min,
            'max': max,
            'reduce': reduce,
            'filter': filter,
            'round': round,
            'len': len,
            'set' : set,
            'int': int

In my opinion this should be implemented in a launchpad branch as I believe int function have no security risks and is a very common function

If you modify the code in the given location, you might loose your modifications when you upgrade your installation of openERP.

on 7/9/13, 8:10 AM

you would certainly lose the modifications and you have to copy that again, or make a custom module.

on 7/10/13, 2:09 PM

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

0 follower(s)


Asked: 7/3/13, 11:40 AM
Seen: 3292 times
Last updated: 3/16/15, 8:10 AM