Browse Source

Merge pull request #3 from akretion/wip_mem_8-attachm-meta

Wip mem 8 attachm meta
pull/376/head
David Beal 9 years ago
parent
commit
f9984fcb70
  1. 8
      attachment_metadata/__openerp__.py
  2. 21
      attachment_metadata/models/attachment.py
  3. 73
      attachment_metadata/views/attachment_view.xml
  4. 1
      oca_dependencies.txt

8
attachment_metadata/__openerp__.py

@ -2,16 +2,13 @@
# @ 2015 Valentin CHEMIERE @ Akretion # @ 2015 Valentin CHEMIERE @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{'name': 'Attachment Metadata',
{
'name': 'Attachment Metadata',
'version': '8.0.1.0.0', 'version': '8.0.1.0.0',
'author': 'Akretion,Odoo Community Association (OCA)', 'author': 'Akretion,Odoo Community Association (OCA)',
'website': 'www.akretion.com', 'website': 'www.akretion.com',
'license': 'AGPL-3', 'license': 'AGPL-3',
'category': 'Generic Modules', 'category': 'Generic Modules',
'description': """
Add some useful field to ir.attachment object like:
internal and external hash for coherence verification
""",
'depends': [ 'depends': [
], ],
'data': [ 'data': [
@ -20,4 +17,5 @@
], ],
'installable': True, 'installable': True,
'application': False, 'application': False,
'images': [],
} }

21
attachment_metadata/models/attachment.py

@ -25,12 +25,27 @@ class IrAttachmentMetadata(models.Model):
attachment_id = fields.Many2one( attachment_id = fields.Many2one(
'ir.attachment', required=True, ondelete='cascade', 'ir.attachment', required=True, ondelete='cascade',
help="Link to ir.attachment model ") 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') @api.depends('datas', 'external_hash')
def _compute_hash(self): 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:
for attachment in self:
if attachment.datas:
attachment.internal_hash = hashlib.md5(
b64decode(self.datas)).hexdigest()
if attachment.external_hash and\
attachment.internal_hash != attachment.external_hash:
raise UserError( raise UserError(
_("File corrupted: Something was wrong with " _("File corrupted: Something was wrong with "
"the retrieved file, please relaunch the task.")) "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')]

73
attachment_metadata/views/attachment_view.xml

@ -9,9 +9,82 @@
<field name="url" position="after"> <field name="url" position="after">
<field name="internal_hash"/> <field name="internal_hash"/>
<field name="external_hash"/> <field name="external_hash"/>
<field name="file_type"/>
</field> </field>
</field> </field>
</record> </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> </data>
</openerp> </openerp>

1
oca_dependencies.txt

@ -0,0 +1 @@
server-tools-file https://github.com/akretion/server-tools.git 8-file-loc
Loading…
Cancel
Save