← Back to team overview

openerp-india team mailing list archive

[Bug 1051550] Re: int and float missing from hr_payroll.tools.safe_eval context

 

Try this:

Condition Based On: Always True

Amount Type: Python Code

Python Code: result = int(13.5 * 11.9)

this will fail


Compare to:

Python Code: result = round(13.5 * 11.9)

which will work, but gives a different answer.


See: tools.safe_eval.py, line 216:

    globals_dict.update(                                                                                                   
            __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
          }
)

Need to add:

                'int': int,
                'float': float,

and similar.

** Description changed:

  I have attempted to implement local tax rules using a series of salary
  rules, but to correctly calculate values for Australian taxes, I need
  access to something that will strip cents from a calculated figure.
  
- int() does this nicely, but it is not listed in
- hr_payoll.tools.safe_eval as one of the allowed builtins. But bool, str,
- tuple, dict and several others are.
+ int() does this nicely, but it is not listed in tools.safe_eval as one
+ of the allowed builtins. But bool, str, tuple, dict and several others
+ are.
  
  Please add in all the safe but useful builtins, like int() and float()
  if you insist on monkey patching eval().
  
  This is in OpenERP 6.1

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/1051550

Title:
  int and float missing from hr_payroll.tools.safe_eval context

Status in OpenERP Addons (modules):
  Incomplete

Bug description:
  I have attempted to implement local tax rules using a series of salary
  rules, but to correctly calculate values for Australian taxes, I need
  access to something that will strip cents from a calculated figure.

  int() does this nicely, but it is not listed in tools.safe_eval as one
  of the allowed builtins. But bool, str, tuple, dict and several others
  are.

  Please add in all the safe but useful builtins, like int() and float()
  if you insist on monkey patching eval().

  This is in OpenERP 6.1

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/1051550/+subscriptions


References