diff --git a/attachment_metadata/README.rst b/attachment_metadata/README.rst new file mode 100644 index 000000000..5abfa0cc4 --- /dev/null +++ b/attachment_metadata/README.rst @@ -0,0 +1,84 @@ + +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +==================== +Attachment Metadata +==================== + +This module extend ir.attachment model with some new fields for a better control +for import and export of files. + +The main feature is an integrity file check with a hash. + +A file hash is short representation (signature) computed from file data. +Hashes computed before send file and after received file can be compared to be +sure of the content integrity. + +An example of the use of this module, can be found in the external_file_location. + + +Usage +===== + +Go the menu Settings > Attachments + +You can create / see standard attachments with additional fields + + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/149/8.0 + + +Known issues / Roadmap +====================== + +The purpose of this module is not to import the data of the file but only exchange files with external application. + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed `feedback +`_. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + + +Contributors +------------ + +* Valentin CHEMIERE +* Sebastien BEAU +* Joel Grand-Guillaume Camptocamp +* initOS + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/attachment_metadata/__init__.py b/attachment_metadata/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/attachment_metadata/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/attachment_metadata/__openerp__.py b/attachment_metadata/__openerp__.py new file mode 100644 index 000000000..23b3d6795 --- /dev/null +++ b/attachment_metadata/__openerp__.py @@ -0,0 +1,21 @@ +# coding: utf-8 +# @ 2015 Valentin CHEMIERE @ Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Attachment Metadata', + 'version': '8.0.1.0.0', + 'author': 'Akretion,Odoo Community Association (OCA)', + 'website': 'www.akretion.com', + 'license': 'AGPL-3', + 'category': 'Generic Modules', + 'depends': [ + ], + 'data': [ + 'views/attachment_view.xml', + 'security/ir.model.access.csv', + ], + 'installable': True, + 'application': False, + 'images': [], +} diff --git a/attachment_metadata/models/__init__.py b/attachment_metadata/models/__init__.py new file mode 100644 index 000000000..c14c86359 --- /dev/null +++ b/attachment_metadata/models/__init__.py @@ -0,0 +1 @@ +from . import attachment diff --git a/attachment_metadata/models/attachment.py b/attachment_metadata/models/attachment.py new file mode 100644 index 000000000..6fd9d52b0 --- /dev/null +++ b/attachment_metadata/models/attachment.py @@ -0,0 +1,51 @@ +# coding: utf-8 +# Copyright (C) 2014 initOS GmbH & Co. KG (). +# @author: Joel Grand-Guillaume @ Camptocamp SA +# @ 2015 Valentin CHEMIERE @ Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, fields, api, _ +from openerp.exceptions import Warning as UserError +import hashlib +from base64 import b64decode + + +class IrAttachmentMetadata(models.Model): + _name = 'ir.attachment.metadata' + _inherits = {'ir.attachment': 'attachment_id'} + + internal_hash = fields.Char( + store=True, compute='_compute_hash', + help="File hash computed with file data to be compared " + "to external hash when provided.") + external_hash = fields.Char( + help="File hash comes from the external owner of the file.\n" + "If provided allow to check than downloaded file " + "is the exact copy of the original file.") + attachment_id = fields.Many2one( + 'ir.attachment', required=True, ondelete='cascade', + help="Link to ir.attachment model ") + file_type = fields.Selection( + selection="_get_file_type", + string="File type", + help="The file type determines an import method to be used " + "to parse and transform data before their import in ERP") + + @api.depends('datas', 'external_hash') + def _compute_hash(self): + for attachment in self: + if attachment.datas: + attachment.internal_hash = hashlib.md5( + b64decode(attachment.datas)).hexdigest() + if attachment.external_hash and\ + attachment.internal_hash != attachment.external_hash: + raise UserError( + _("File corrupted: Something was wrong with " + "the retrieved file, please relaunch the task.")) + + def _get_file_type(self): + """This is the method to be inherited for adding file types + The basic import do not apply any parsing or transform of the file. + The file is just added as an attachement + """ + return [('basic_import', 'Basic import')] diff --git a/attachment_metadata/security/ir.model.access.csv b/attachment_metadata/security/ir.model.access.csv new file mode 100644 index 000000000..9b01638c4 --- /dev/null +++ b/attachment_metadata/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_attachment_metadata_user,ir.attachment.metadata.user,model_ir_attachment_metadata,base.group_user,1,0,0,0 diff --git a/attachment_metadata/views/attachment_view.xml b/attachment_metadata/views/attachment_view.xml new file mode 100644 index 000000000..71ed3a2cd --- /dev/null +++ b/attachment_metadata/views/attachment_view.xml @@ -0,0 +1,90 @@ + + + + + + ir.attachment.metadata + + + + + + + + + + + + ir.attachment.metadata + + + + + + + + + + + ir.attachment.metadata + + + + + + + + + + + + + + + + + + + + + + + Meta data Attachments + ir.actions.act_window + ir.attachment.metadata + form + tree,form + + + + + + + tree + + + + + + + form + + + + + + + + +