Browse Source

[FIX] check if class is in installed module, README

pull/515/head
David Beal 9 years ago
committed by Florian da Costa
parent
commit
528f6e3fc4
  1. 66
      attachment_metadata/README.rst
  2. 21
      attachment_metadata/attachment.py
  3. 24
      attachment_metadata/attachment_view.xml

66
attachment_metadata/README.rst

@ -1,51 +1,77 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
====================
Attachment Metadata
======================
This module was written to extend the functionality of ir.attachment
====================
Installation
============
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.
Installable without any requirements
Usage
=====
THe module just add some field to ir.attachment
Go the menu Settings > Attachments
You can create / see standard attachments with additional fields
For further information, please visit:
* https://www.odoo.com/forum/help-1
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/{repo_id}/8.0
.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
.. branch is "8.0" for example
Known issues / Roadmap
======================
* ...
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/connector-interfaces/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/
connector-interfaces/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
=======
* Joel Grand-Guillaume Camptocamp
* initOS <http://initos.com>
* Valentin CHEMIERE <valentin.chemiere@akretion.com>
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
----------
* Valentin CHEMIERE <valentin.chemiere@akretion.com>
.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
.. 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.
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.
To contribute to this module, please visit https://odoo-community.org.

21
attachment_metadata/attachment.py

@ -14,16 +14,23 @@ 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')
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 ")
@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 UserError(_('File corrupted'),
_("Something was wrong with the retreived file, "
"please relaunch the task."))
raise UserError(
_("File corrupted: Something was wrong with "
"the retrieved file, please relaunch the task."))

24
attachment_metadata/attachment_view.xml

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<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>
<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>
</data>
</openerp>
Loading…
Cancel
Save