diff --git a/attachment_s3/models/ir_attachment.py b/attachment_s3/models/ir_attachment.py index 2fe55a4..0513291 100644 --- a/attachment_s3/models/ir_attachment.py +++ b/attachment_s3/models/ir_attachment.py @@ -90,7 +90,7 @@ class IrAttachment(models.Model): if fname: self._file_delete(fname) continue - self._data_set('datas', attach.datas, None) + attach._data_set('datas', attach.datas, None) def _register_hook(self, cr): super(IrAttachment, self)._register_hook(cr) diff --git a/base_attachment_object_storage/models/ir_attachment.py b/base_attachment_object_storage/models/ir_attachment.py index 8ece688..6fc56ea 100644 --- a/base_attachment_object_storage/models/ir_attachment.py +++ b/base_attachment_object_storage/models/ir_attachment.py @@ -9,7 +9,7 @@ import psycopg2 import odoo from contextlib import closing, contextmanager -from openerp import api, exceptions, models, _ +from openerp import api, exceptions, fields, models, _ from openerp import SUPERUSER_ID @@ -40,6 +40,19 @@ class IrAttachment(models.Model): _local_fields = ('image_small', 'image_medium', 'web_icon_data') + datas = fields.Binary( + compute='_compute_datas', + inverse='_inverse_datas', + string='File Content', + nodrop=True, + ) + + @api.depends('store_fname', 'db_datas') + def _compute_datas(self): + values = self._data_get('datas', None) + for attach in self: + attach.datas = values.get(attach.id) + @api.cr def _register_hook(self, cr): super(IrAttachment, self)._register_hook(cr) @@ -128,7 +141,7 @@ class IrAttachment(models.Model): if fname: self._file_delete(fname) continue - super(IrAttachment, attach)._inverse_datas() + attach._data_set('datas', attach.datas, None) @api.model def _file_read(self, fname, bin_size=False):