Valentin Chemiere
10 years ago
committed by
Florian da Costa
6 changed files with 183 additions and 0 deletions
-
51attachment_metadata/README.rst
-
23attachment_metadata/__init__.py
-
43attachment_metadata/__openerp__.py
-
47attachment_metadata/attachment.py
-
17attachment_metadata/attachment_view.xml
-
2attachment_metadata/security/ir.model.access.csv
@ -0,0 +1,51 @@ |
|||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
|||
:alt: License |
|||
|
|||
Attachment Metadata |
|||
====================== |
|||
|
|||
This module was written to extend the functionality of ir.attachment |
|||
|
|||
Installation |
|||
============ |
|||
|
|||
Installable without any requirements |
|||
|
|||
Usage |
|||
===== |
|||
|
|||
THe module just add some field to ir.attachment |
|||
|
|||
For further information, please visit: |
|||
|
|||
* https://www.odoo.com/forum/help-1 |
|||
|
|||
Known issues / Roadmap |
|||
====================== |
|||
|
|||
Credits |
|||
======= |
|||
|
|||
* Joel Grand-Guillaume Camptocamp |
|||
* initOS <http://initos.com> |
|||
* Valentin CHEMIERE <valentin.chemiere@akretion.com> |
|||
|
|||
Contributors |
|||
------------ |
|||
|
|||
* Sebastien BEAU <sebastian.beau@akretion.com> |
|||
|
|||
Maintainer |
|||
---------- |
|||
|
|||
* Valentin CHEMIERE <valentin.chemiere@akretion.com> |
|||
|
|||
.. image:: http://odoo-community.org/logo.png |
|||
:alt: Odoo Community Association |
|||
:target: http://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 http://odoo-community.org. |
@ -0,0 +1,23 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Module for OpenERP |
|||
# Copyright (C) 2015 Akretion (http://www.akretion.com). |
|||
# @author Valentin CHEMIERE <valentin.chemiere@akretion.com> |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
|
|||
from . import attachment |
@ -0,0 +1,43 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Module for OpenERP |
|||
# Copyright (C) 2015 Akretion (http://www.akretion.com). |
|||
# @author Valentin CHEMIERE <valentin.chemiere@akretion.com> |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
|
|||
{'name': 'attachment_metadata', |
|||
'version': '0.0.1', |
|||
'author': 'Akretion', |
|||
'website': 'www.akretion.com', |
|||
'license': 'AGPL-3', |
|||
'category': 'Generic Modules', |
|||
'description': """ |
|||
Add some useful field to ir.attachment object like: |
|||
internal and external hash for coherence verification |
|||
""", |
|||
'depends': [ |
|||
'base', |
|||
'mail' |
|||
], |
|||
'data': [ |
|||
'attachment_view.xml', |
|||
'security/ir.model.access.csv', |
|||
], |
|||
'installable': True, |
|||
'application': False, |
|||
} |
@ -0,0 +1,47 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Module for OpenERP |
|||
# Copyright 2011-2012 Camptocamp SA |
|||
# @author: Joel Grand-Guillaume |
|||
# Copyright (C) 2015 Akretion (http://www.akretion.com). |
|||
# @author Valentin CHEMIERE <valentin.chemiere@akretion.com> |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU Affero General Public License |
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################### |
|||
|
|||
from openerp import models, fields, api, _ |
|||
from openerp.exceptions import Warning |
|||
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') |
|||
external_hash = fields.Char() |
|||
attachment_id = fields.Many2one('ir.attachment', required=True, |
|||
ondelete='cascade') |
|||
|
|||
@api.depends('datas', 'external_hash') |
|||
def _compute_hash(self): |
|||
if self.datas: |
|||
self.internal_hash = hashlib.md5(b64decode(self.datas)).hexdigest() |
|||
if self.external_hash and self.internal_hash != self.external_hash: |
|||
raise Warning(_('File corrupted'), |
|||
_("Something was wrong with the retreived file, " |
|||
"please relaunch the task.")) |
@ -0,0 +1,17 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<openerp> |
|||
<data> |
|||
|
|||
<record id="view_attachment_improved_form" model="ir.ui.view"> |
|||
<field name="model">ir.attachment.metadata</field> |
|||
<field name="inherit_id" ref="base.view_attachment_form" /> |
|||
<field name="arch" type="xml"> |
|||
<field name="url" position="after"> |
|||
<field name="internal_hash"/> |
|||
<field name="external_hash"/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
</data> |
|||
</openerp> |
@ -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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue