Browse Source

publish muk_attachment_lobject - 12.0

pull/9/head
MuK IT GmbH 6 years ago
parent
commit
f4a90da358
  1. 2
      muk_attachment_lobject/__manifest__.py
  2. 35
      muk_attachment_lobject/models/ir_attachment.py

2
muk_attachment_lobject/__manifest__.py

@ -20,7 +20,7 @@
{ {
"name": "MuK Large Objects Attachment", "name": "MuK Large Objects Attachment",
"summary": """Large Objects Attachment Location""", "summary": """Large Objects Attachment Location""",
"version": '12.0.2.1.2',
"version": '12.0.2.1.3',
"category": 'Extra Tools', "category": 'Extra Tools',
"license": "AGPL-3", "license": "AGPL-3",
"website": "http://www.mukit.at", "website": "http://www.mukit.at",

35
muk_attachment_lobject/models/ir_attachment.py

@ -32,9 +32,27 @@ class LObjectIrAttachment(models.Model):
_inherit = 'ir.attachment' _inherit = 'ir.attachment'
#----------------------------------------------------------
# Database
#----------------------------------------------------------
store_lobject = LargeObject( store_lobject = LargeObject(
string="Data") 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 @api.model
def storage_locations(self): def storage_locations(self):
locations = super(LObjectIrAttachment, self).storage_locations() locations = super(LObjectIrAttachment, self).storage_locations()
@ -57,7 +75,11 @@ class LObjectIrAttachment(models.Model):
] ]
self.search(record_domain).migrate() self.search(record_domain).migrate()
return True return True
#----------------------------------------------------------
# Read
#----------------------------------------------------------
@api.depends('store_lobject') @api.depends('store_lobject')
def _compute_datas(self): def _compute_datas(self):
bin_size = self._context.get('bin_size') bin_size = self._context.get('bin_size')
@ -70,20 +92,23 @@ class LObjectIrAttachment(models.Model):
else: else:
super(LObjectIrAttachment, attach)._compute_datas() super(LObjectIrAttachment, attach)._compute_datas()
#----------------------------------------------------------
# Create, Write, Delete
#----------------------------------------------------------
def _inverse_datas(self): def _inverse_datas(self):
location = self._storage() location = self._storage()
for attach in self: for attach in self:
if location == 'lobject': if location == 'lobject':
value = attach.datas value = attach.datas
bin_data = base64.b64decode(value) if value else b'' bin_data = base64.b64decode(value) if value else b''
vals = {
vals = self._get_datas_inital_vals()
vals.update({
'file_size': len(bin_data), 'file_size': len(bin_data),
'checksum': self._compute_checksum(bin_data), 'checksum': self._compute_checksum(bin_data),
'index_content': self._index(bin_data, attach.datas_fname, attach.mimetype), 'index_content': self._index(bin_data, attach.datas_fname, attach.mimetype),
'store_fname': False,
'db_datas': False,
'store_lobject': bin_data, 'store_lobject': bin_data,
}
})
fname = attach.store_fname fname = attach.store_fname
super(LObjectIrAttachment, attach.sudo()).write(vals) super(LObjectIrAttachment, attach.sudo()).write(vals)
if fname: if fname:

Loading…
Cancel
Save