Odoo Help


Open custom binary file

on 1/14/16, 4:48 AM 993 views

Hi. I trying to save some data to Binary field for the sake to open it in browser and save on computer. Code is like this:

# -*- coding: utf-8 -*-

from openerp import api, fields, models

 import base64

import cStringIO

class ExportInvoice1C(models.Model):

_name = "account.invoice.export.1c"

_description = "Exports invoice for 1c client bank"

  mdata = fields.Binary('File', readonly=True)



def default_get(self, fields):

f = cStringIO.StringIO()


out = base64.encodestring(f.getvalue())

self.mdata = out

res = super(ExportInvoice1C, self).default_get(self, fields)

res.update({'mdata': self.mdata})

return res

Then i got error on line self.mdata = out :

raise ValueError("Expected singleton: %s" % self)

ValueError: Expected singleton: account.invoice.export.1c()

Why i cant write binary file to this field ?

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

1 follower(s)


Asked: 1/14/16, 4:48 AM
Seen: 993 times
Last updated: 1/14/16, 4:58 AM