[MERGE] Fix bug 891544 - prevent double-encoding of binary fields
authorOlivier Dony <odo@openerp.com>
Mon, 28 Nov 2011 12:45:35 +0000 (13:45 +0100)
committerOlivier Dony <odo@openerp.com>
Mon, 28 Nov 2011 12:45:35 +0000 (13:45 +0100)
lp bug: https://launchpad.net/bugs/891544 fixed

bzr revid: odo@openerp.com-20111128124535-s8cesplj379ssfqm

1  2 
openerp/osv/fields.py
openerp/report/report_sxw.py

@@@ -1015,10 -1015,10 +1015,10 @@@ class function(_column)
                  result = (value, dict_names[value])
  
          if field_type == 'binary':
--            if context.get('bin_size', False):
++            if context.get('bin_size'):
                  # client requests only the size of binary fields
                  result = get_nice_size(value)
-             else:
+             elif not context.get('bin_raw'):
                  result = sanitize_binary_value(value)
  
          if field_type in ("integer","integer_big") and value > xmlrpclib.MAXINT:
@@@ -391,8 -391,12 +391,12 @@@ class report_sxw(report_rml, preprocess
          return table_obj.browse(cr, uid, ids, list_class=browse_record_list, context=context, fields_process=_fields_process)
  
      def create(self, cr, uid, ids, data, context=None):
+         if context is None:
+             context = {}
          if self.internal_header:
--            context.update({'internal_header':self.internal_header})
 -        #we ask osv.fields.sanitize_binary_value() not to encode the binary value"
 -        context.update({'bin_raw':True})
++            context.update(internal_header=self.internal_header)
++        # skip osv.fields.sanitize_binary_value() because we want the raw bytes in all cases
++        context.update(bin_raw=True)
          pool = pooler.get_pool(cr.dbname)
          ir_obj = pool.get('ir.actions.report.xml')
          report_xml_ids = ir_obj.search(cr, uid,