mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 02:08:36 +00:00
[ADD] delivery_carrier_label_s3 module
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
Shipping label S3
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
* Add s3 location management for shipping label.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# © 2017 Joel Grand-Guillaume (Camptocamp)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from . import models
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# © 2017 Joel Grand-Guillaume (Camptocamp)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
{
|
||||||
|
'name': 'Specific - Shipping Label',
|
||||||
|
'version': '9.0.1.0.0',
|
||||||
|
'author': 'Camptocamp',
|
||||||
|
'license': 'AGPL-3',
|
||||||
|
'category': 'Knowledge Management',
|
||||||
|
'website': 'http://www.camptocamp.com',
|
||||||
|
'images': [],
|
||||||
|
'depends': [
|
||||||
|
'base_delivery_carrier_label',
|
||||||
|
'attachment_s3',
|
||||||
|
],
|
||||||
|
'data': [
|
||||||
|
],
|
||||||
|
'test': [],
|
||||||
|
'installable': True,
|
||||||
|
'auto_install': True,
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# © 2017 Vincent Renaville (Camptocamp)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from . import shipping_label
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from openerp import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class ShippingLabel(models.Model):
|
||||||
|
""" Inherit of shipping label to store datas in the right location if S3 activated """
|
||||||
|
|
||||||
|
_inherit = 'shipping.label'
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
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
|
||||||
|
location = self.attachment_id._storage()
|
||||||
|
for attach in self:
|
||||||
|
if location == 's3' and self._store_in_db_when_s3():
|
||||||
|
# compute the fields that depend on datas
|
||||||
|
value = attach.datas
|
||||||
|
bin_data = value and value.decode('base64') or ''
|
||||||
|
vals = {
|
||||||
|
'file_size': len(bin_data),
|
||||||
|
'checksum': self._compute_checksum(bin_data),
|
||||||
|
'db_datas': value,
|
||||||
|
# we seriously don't need index content on those fields
|
||||||
|
'index_content': False,
|
||||||
|
'store_fname': False,
|
||||||
|
}
|
||||||
|
fname = attach.store_fname
|
||||||
|
# write as superuser, as user probably does not
|
||||||
|
# have write access
|
||||||
|
super(ShippingLabel, attach.sudo()).write(vals)
|
||||||
|
if fname:
|
||||||
|
self._file_delete(fname)
|
||||||
|
continue
|
||||||
|
self.attachment_id._data_set('datas', attach.datas, None)
|
||||||
Reference in New Issue
Block a user