Browse Source

Merge pull request #376 from akretion/8-attachm-meta

8 module attachment metadata
pull/448/head
beau sebastien 9 years ago
parent
commit
885afb813a
  1. 84
      attachment_metadata/README.rst
  2. 1
      attachment_metadata/__init__.py
  3. 21
      attachment_metadata/__openerp__.py
  4. 1
      attachment_metadata/models/__init__.py
  5. 51
      attachment_metadata/models/attachment.py
  6. 2
      attachment_metadata/security/ir.model.access.csv
  7. 90
      attachment_metadata/views/attachment_view.xml

84
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
<https://github.com/OCA/server-tools/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
<https://github.com/OCA/
server-tools/issues/new?body=module:%20
attachment_metadata%0Aversion:%20
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Valentin CHEMIERE <valentin.chemiere@akretion.com>
* Sebastien BEAU <sebastian.beau@akretion.com>
* Joel Grand-Guillaume Camptocamp
* initOS <http://initos.com>
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.

1
attachment_metadata/__init__.py

@ -0,0 +1 @@
from . import models

21
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': [],
}

1
attachment_metadata/models/__init__.py

@ -0,0 +1 @@
from . import attachment

51
attachment_metadata/models/attachment.py

@ -0,0 +1,51 @@
# coding: utf-8
# Copyright (C) 2014 initOS GmbH & Co. KG (<http://www.initos.com>).
# @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')]

2
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

90
attachment_metadata/views/attachment_view.xml

@ -0,0 +1,90 @@
<?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 name="file_type"/>
</field>
</field>
</record>
<record id="view_external_attachment_tree" model="ir.ui.view">
<field name="model">ir.attachment.metadata</field>
<field name="arch" type="xml">
<tree string="Attachments" >
<field name="name"/>
<field name="datas_fname"/>
<field name="file_type"/>
</tree>
</field>
</record>
<record id="view_external_attachment_search" model="ir.ui.view">
<field name="model">ir.attachment.metadata</field>
<field name="arch" type="xml">
<search string="Attachments">
<field name="name" filter_domain="['|', ('name','ilike',self), ('datas_fname','ilike',self)]" string="Attachment"/>
<field name="create_date"/>
<filter icon="terp-stage"
string="URL"
domain="[('type','=','url')]"/>
<filter icon="terp-stock_align_left_24"
string="Binary"
domain="[('type','=','binary')]"/>
<separator/>
<filter name="my_documents_filter"
string="My Document(s)"
icon="terp-personal"
domain="[('create_uid','=',uid)]"
help="Filter on my documents"/>
<field name="create_uid"/>
<field name="type"/>
<group expand="0" string="Group By">
<filter string="Owner" icon="terp-personal" domain="[]" context="{'group_by':'create_uid'}"/>
<filter string="Type" icon="terp-stock_symbol-selection" domain="[]" context="{'group_by':'type'}" groups="base.group_no_one"/>
<filter string="Company" icon="terp-gtk-home" domain="[]" context="{'group_by':'company_id'}" groups="base.group_multi_company"/>
<filter string="Creation Month" icon="terp-go-month" domain="[]" context="{'group_by':'create_date'}"/>
<filter string="File type" domain="[]" context="{'group_by': 'file_type'}"/>
</group>
</search>
</field>
</record>
<record id="action_attachment" model="ir.actions.act_window">
<field name="name">Meta data Attachments</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">ir.attachment.metadata</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" eval="False"/>
<field name="search_view_id" ref="view_external_attachment_search"/>
</record>
<record id="ir_attachment_view2" model="ir.actions.act_window.view">
<field eval="10" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_external_attachment_tree"/>
<field name="act_window_id" ref="action_attachment"/>
</record>
<record id="ir_attachment_view3" model="ir.actions.act_window.view">
<field eval="10" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="view_attachment_improved_form"/>
<field name="act_window_id" ref="action_attachment"/>
</record>
<menuitem id="menu_ir_attachment"
parent="base.next_id_9"
sequence="20"
action="action_attachment"/>
</data>
</openerp>
Loading…
Cancel
Save