From f2a0c090d21649f1115197e62eb17a2dfd49a5ad Mon Sep 17 00:00:00 2001 From: MuK IT GmbH Date: Thu, 14 Feb 2019 18:52:19 +0000 Subject: [PATCH] publish muk_utils - 12.0 --- muk_utils/__manifest__.py | 2 +- muk_utils/models/ir_attachment.py | 39 +++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/muk_utils/__manifest__.py b/muk_utils/__manifest__.py index 5a154f7..b2b7cb5 100644 --- a/muk_utils/__manifest__.py +++ b/muk_utils/__manifest__.py @@ -19,7 +19,7 @@ { "name": "MuK Utils", "summary": """Utility Features""", - "version": '12.0.1.4.17', + "version": '12.0.1.4.18', "category": 'Extra Tools', "license": "AGPL-3", "author": "MuK IT", diff --git a/muk_utils/models/ir_attachment.py b/muk_utils/models/ir_attachment.py index 0a054a8..98ede00 100644 --- a/muk_utils/models/ir_attachment.py +++ b/muk_utils/models/ir_attachment.py @@ -27,10 +27,21 @@ from odoo.tools.mimetypes import guess_mimetype _logger = logging.getLogger(__name__) -class Attachment(models.Model): +class IrAttachment(models.Model): _inherit = 'ir.attachment' + #---------------------------------------------------------- + # Helper + #---------------------------------------------------------- + + @api.model + def _get_datas_inital_vals(self): + return { + 'store_fname': False, + 'db_datas': False, + } + #---------------------------------------------------------- # Functions #---------------------------------------------------------- @@ -70,5 +81,29 @@ class Attachment(models.Model): if self.env.context.get('migration') and len(self) == 1: return self.mimetype or 'application/octet-stream' else: - return super(Attachment, self)._compute_mimetype(values) + return super(IrAttachment, self)._compute_mimetype(values) + + #---------------------------------------------------------- + # Create, Write, Delete + #---------------------------------------------------------- + + def _inverse_datas(self): + location = self._storage() + for attach in self: + value = attach.datas + bin_data = base64.b64decode(value) if value else b'' + 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), + }) + if value and location != 'db': + vals['store_fname'] = self._file_write(value, vals['checksum']) + else: + vals['db_datas'] = value + fname = attach.store_fname + super(IrAttachment, attach.sudo()).write(vals) + if fname: + self._file_delete(fname) \ No newline at end of file