Mathias Markl 7 years ago
parent
commit
44ef1be412
  1. 9
      muk_attachment_lobject/models/ir_attachment.py
  2. 3
      muk_fields_lobject/fields.py

9
muk_attachment_lobject/models/ir_attachment.py

@ -35,6 +35,8 @@ from odoo.exceptions import AccessError, ValidationError
from odoo.tools import config, human_size, ustr, html_escape
from odoo.tools.mimetypes import guess_mimetype
from odoo.addons.muk_fields_lobject import fields as lobject_fields
_logger = logging.getLogger(__name__)
class LObjectIrAttachment(models.Model):
@ -54,12 +56,15 @@ class LObjectIrAttachment(models.Model):
attach.write({'datas': attach.datas})
return True
@api.depends('store_fname', 'db_datas', 'store_document')
@api.depends('store_fname', 'db_datas', 'store_lobject')
def _compute_datas(self):
bin_size = self._context.get('bin_size')
for attach in self:
if attach.store_lobject:
attach.datas = base64.b64encode(attach.store_lobject)
if bin_size:
attach.datas = attach.store_lobject
else:
attach.datas = base64.b64encode(attach.store_lobject)
else:
super(LObjectIrAttachment, attach)._compute_datas()

3
muk_fields_lobject/fields.py

@ -41,6 +41,9 @@ class LargeObject(fields.Field):
}
def convert_to_column(self, value, record, values=None):
oid = record.with_context({'oid': True})[self.name]
if oid:
record.env.cr._cnx.lobject(oid, 'rb').unlink()
if not value:
return None
lobject = record.env.cr._cnx.lobject(0, 'wb')

Loading…
Cancel
Save