Odoo Help


This community 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.


Open custom binary file

on 1/14/16, 4:48 AM 413 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 ?

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


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