mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 08:47:40 +00:00
[IMP] adapt features to v12
This commit is contained in:
@@ -4,13 +4,15 @@
|
|||||||
|
|
||||||
{'name': 'Base Attachment Object Store',
|
{'name': 'Base Attachment Object Store',
|
||||||
'summary': 'Base module for the implementation of external object store.',
|
'summary': 'Base module for the implementation of external object store.',
|
||||||
'version': '12.0.1.1.0',
|
'version': '12.0.1.2.0',
|
||||||
'author': 'Camptocamp,Odoo Community Association (OCA)',
|
'author': 'Camptocamp,Odoo Community Association (OCA)',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'category': 'Knowledge Management',
|
'category': 'Knowledge Management',
|
||||||
'depends': ['base'],
|
'depends': ['base'],
|
||||||
'website': 'http://www.camptocamp.com',
|
'website': 'http://www.camptocamp.com',
|
||||||
'data': [],
|
'data': [
|
||||||
|
'data/res_config_settings_data.xml',
|
||||||
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'auto_install': True,
|
'auto_install': True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ class IrAttachment(models.Model):
|
|||||||
domain = OR([domain, part])
|
domain = OR([domain, part])
|
||||||
return domain
|
return domain
|
||||||
|
|
||||||
def _store_in_db_instead_of_object_storage(self, data, mimetype):
|
def _store_in_db_instead_of_object_storage(self):
|
||||||
""" Return whether an attachment must be stored in db
|
""" Return whether an attachment must be stored in db
|
||||||
|
|
||||||
When we are using an Object Storage. This is sometimes required
|
When we are using an Object Storage. This is sometimes required
|
||||||
@@ -157,28 +157,39 @@ class IrAttachment(models.Model):
|
|||||||
"""
|
"""
|
||||||
storage_config = self._get_storage_force_db_config()
|
storage_config = self._get_storage_force_db_config()
|
||||||
for mimetype_key, limit in storage_config.items():
|
for mimetype_key, limit in storage_config.items():
|
||||||
if mimetype.startswith(mimetype_key):
|
if self.mimetype.startswith(mimetype_key):
|
||||||
if not limit:
|
if not limit:
|
||||||
return True
|
return True
|
||||||
bin_data = base64.b64decode(data) if data else b''
|
bin_data = base64.b64decode(self.datas) if self.datas else b''
|
||||||
return len(bin_data) <= limit
|
return len(bin_data) <= limit
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _get_datas_related_values(self, data, mimetype):
|
def _inverse_datas(self):
|
||||||
|
# override in order to store files that need fast access,
|
||||||
|
# we keep them in the database instead of the object storage
|
||||||
storage = self.env.context.get('storage_location') or self._storage()
|
storage = self.env.context.get('storage_location') or self._storage()
|
||||||
if data and storage in self._get_stores():
|
for attach in self:
|
||||||
if self._store_in_db_instead_of_object_storage(data, mimetype):
|
if storage in self._get_stores():
|
||||||
|
if self._store_in_db_instead_of_object_storage():
|
||||||
# compute the fields that depend on datas
|
# compute the fields that depend on datas
|
||||||
bin_data = base64.b64decode(data) if data else b''
|
value = attach.datas
|
||||||
values = {
|
bin_data = base64.b64decode(value) if value else ''
|
||||||
|
vals = {
|
||||||
'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, mimetype),
|
# we seriously don't need index content on those fields
|
||||||
|
'index_content': False,
|
||||||
'store_fname': False,
|
'store_fname': False,
|
||||||
'db_datas': data,
|
'db_datas': value,
|
||||||
}
|
}
|
||||||
return values
|
fname = attach.store_fname
|
||||||
return super()._get_datas_related_values(data, mimetype)
|
# write as superuser, as user probably does not
|
||||||
|
# have write access
|
||||||
|
super(IrAttachment, attach.sudo()).write(vals)
|
||||||
|
if fname:
|
||||||
|
self._file_delete(fname)
|
||||||
|
continue
|
||||||
|
super(IrAttachment, attach)._inverse_datas()
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _file_read(self, fname, bin_size=False):
|
def _file_read(self, fname, bin_size=False):
|
||||||
|
|||||||
Reference in New Issue
Block a user