← Back to team overview

c2c-oerpscenario team mailing list archive

[Bug 723662] Re: Unable to print 0.00 float value on a report

 

The error happens with other reporting engines than the ReportLab. For
example Aeroo Reports are using floating point value directly by using
built in Python's __str__ method, which were overloaded by OpenERP
server.

The method "__str__", when the float value is "0.00" still returns
floating point value, which is against Python conventions:

http://docs.python.org/reference/datamodel.html#object.__str__
Quote> The return value must be a string object.

This is the code from the "report_sxw.py" file, line #77:

class _float_format(float, _format):
    def __init__(self,value):
        super(_float_format, self).__init__()
        self.val = value

    def __str__(self):
        digits = 2
        if hasattr(self,'_field') and getattr(self._field, 'digits', None):
            digits = self._field.digits[1]
        if hasattr(self, 'lang_obj'):
            return self.lang_obj.format('%.' + str(digits) + 'f', self.name, True)
        return self.val


Pay attention to the last line, which evidently does not return string, as it should have.

** Changed in: openobject-server
       Status: Invalid => New

-- 
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/723662

Title:
  Unable to print 0.00 float value on a report

Status in OpenERP Server:
  New

Bug description:
  It is not possible to print float field with value "0.00" on a report,
  though the value eg. "1.00" would print just fine. Throws error that
  it is not possible to coerce value to the Unicode type.

  This problem is present on whole OpenERP 6.x branch and at least on
  OpenERP v5.0.15.

  The root of the problem lies in that there is a special field type
  class defined for automatic formatting purposes, and there is no
  "__repr__" method defined for the class.

  File name: report_sxw.py
  Class name: _float_format
  Line number: ~82



References