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)
@api.model
def default_get(self, fields):
f = cStringIO.StringIO()
f.write('1CClientBankExchange\n')
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 ?