diff --git a/muk_attachment_lobject/__manifest__.py b/muk_attachment_lobject/__manifest__.py index 9e9b60a..6940646 100644 --- a/muk_attachment_lobject/__manifest__.py +++ b/muk_attachment_lobject/__manifest__.py @@ -20,7 +20,7 @@ { "name": "MuK Large Objects Attachment", "summary": """Large Objects Attachment Location""", - "version": '12.0.2.1.2', + "version": '12.0.2.1.3', "category": 'Extra Tools', "license": "AGPL-3", "website": "http://www.mukit.at", diff --git a/muk_attachment_lobject/models/ir_attachment.py b/muk_attachment_lobject/models/ir_attachment.py index 94c8d85..0fcf9d6 100644 --- a/muk_attachment_lobject/models/ir_attachment.py +++ b/muk_attachment_lobject/models/ir_attachment.py @@ -32,9 +32,27 @@ class LObjectIrAttachment(models.Model): _inherit = 'ir.attachment' + #---------------------------------------------------------- + # Database + #---------------------------------------------------------- + store_lobject = LargeObject( string="Data") + #---------------------------------------------------------- + # Helper + #---------------------------------------------------------- + + @api.model + def _get_datas_inital_vals(self): + vals = super(LObjectIrAttachment, self)._get_datas_inital_vals() + vals.update({'store_lobject': False}) + return vals + + #---------------------------------------------------------- + # Function + #---------------------------------------------------------- + @api.model def storage_locations(self): locations = super(LObjectIrAttachment, self).storage_locations() @@ -57,7 +75,11 @@ class LObjectIrAttachment(models.Model): ] self.search(record_domain).migrate() return True - + + #---------------------------------------------------------- + # Read + #---------------------------------------------------------- + @api.depends('store_lobject') def _compute_datas(self): bin_size = self._context.get('bin_size') @@ -70,20 +92,23 @@ class LObjectIrAttachment(models.Model): else: super(LObjectIrAttachment, attach)._compute_datas() + #---------------------------------------------------------- + # Create, Write, Delete + #---------------------------------------------------------- + def _inverse_datas(self): location = self._storage() for attach in self: if location == 'lobject': value = attach.datas bin_data = base64.b64decode(value) if value else b'' - vals = { + vals = self._get_datas_inital_vals() + vals.update({ 'file_size': len(bin_data), 'checksum': self._compute_checksum(bin_data), 'index_content': self._index(bin_data, attach.datas_fname, attach.mimetype), - 'store_fname': False, - 'db_datas': False, 'store_lobject': bin_data, - } + }) fname = attach.store_fname super(LObjectIrAttachment, attach.sudo()).write(vals) if fname: