Browse Source

Migrate and rename attachment_metadata to attachment_base_synchronize

pull/515/head
Florian da Costa 8 years ago
parent
commit
ff1896eab3
  1. 0
      attachment_base_synchronize/README.rst
  2. 0
      attachment_base_synchronize/__init__.py
  3. 8
      attachment_base_synchronize/__openerp__.py
  4. 18
      attachment_base_synchronize/data/cron.xml
  5. 0
      attachment_base_synchronize/i18n/de.po
  6. 0
      attachment_base_synchronize/i18n/en.po
  7. 0
      attachment_base_synchronize/i18n/es.po
  8. 0
      attachment_base_synchronize/i18n/fi.po
  9. 0
      attachment_base_synchronize/i18n/fr.po
  10. 6
      attachment_base_synchronize/i18n/it.po
  11. 0
      attachment_base_synchronize/i18n/pt_BR.po
  12. 0
      attachment_base_synchronize/i18n/ru.po
  13. 0
      attachment_base_synchronize/i18n/sl.po
  14. 0
      attachment_base_synchronize/i18n/tr.po
  15. 0
      attachment_base_synchronize/i18n/zh_CN.po
  16. 0
      attachment_base_synchronize/models/__init__.py
  17. 104
      attachment_base_synchronize/models/attachment.py
  18. 0
      attachment_base_synchronize/security/ir.model.access.csv
  19. 24
      attachment_base_synchronize/views/attachment_view.xml
  20. 51
      attachment_metadata/models/attachment.py

0
attachment_metadata/README.rst → attachment_base_synchronize/README.rst

0
attachment_metadata/__init__.py → attachment_base_synchronize/__init__.py

8
attachment_metadata/__openerp__.py → attachment_base_synchronize/__openerp__.py

@ -1,19 +1,21 @@
# coding: utf-8
# @ 2015 Valentin CHEMIERE @ Akretion
# @ 2015 Florian DA COSTA @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Attachment Metadata',
'version': '8.0.1.0.0',
'name': 'Attachment Base Synchronize',
'version': '9.0.1.0.0',
'author': 'Akretion,Odoo Community Association (OCA)',
'website': 'www.akretion.com',
'license': 'AGPL-3',
'category': 'Generic Modules',
'depends': [
'base',
],
'data': [
'views/attachment_view.xml',
'security/ir.model.access.csv',
'data/cron.xml',
],
'installable': True,
'application': False,

18
attachment_base_synchronize/data/cron.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data noupdate="1">
<record model="ir.cron" id="cronjob_run_attachments_metadata">
<field name='name'>Run Attachments Metadata</field>
<field name='interval_number'>30</field>
<field name='interval_type'>minutes</field>
<field name="numbercall">-1</field>
<field name="active">False</field>
<field name="doall" eval="False" />
<field name="model">ir.attachment.metadata</field>
<field name="function">run_attachment_metadata_scheduler</field>
<field name="args">([])</field>
</record>
</data>
</openerp>

0
attachment_metadata/i18n/de.po → attachment_base_synchronize/i18n/de.po

0
attachment_metadata/i18n/en.po → attachment_base_synchronize/i18n/en.po

0
attachment_metadata/i18n/es.po → attachment_base_synchronize/i18n/es.po

0
attachment_metadata/i18n/fi.po → attachment_base_synchronize/i18n/fi.po

0
attachment_metadata/i18n/fr.po → attachment_base_synchronize/i18n/fr.po

6
attachment_metadata/i18n/it.po → attachment_base_synchronize/i18n/it.po

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: server-tools (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-07-28 00:59+0000\n"
"POT-Creation-Date: 2016-06-09 18:30+0000\n"
"PO-Revision-Date: 2016-06-01 09:37+0000\n"
"Last-Translator: <>\n"
"Language-Team: Italian (http://www.transifex.com/oca/OCA-server-tools-8-0/language/it/)\n"
@ -82,7 +82,7 @@ msgstr "Descrizione"
#. module: attachment_metadata
#: field:ir.attachment.metadata,display_name:0
msgid "Display Name"
msgstr "Nome da visualizzare"
msgstr ""
#. module: attachment_metadata
#: field:ir.attachment.metadata,external_hash:0
@ -155,7 +155,7 @@ msgstr ""
#. module: attachment_metadata
#: field:ir.attachment.metadata,__last_update:0
msgid "Last Modified on"
msgstr "Ultima modifica il"
msgstr ""
#. module: attachment_metadata
#: field:ir.attachment.metadata,write_uid:0

0
attachment_metadata/i18n/pt_BR.po → attachment_base_synchronize/i18n/pt_BR.po

0
attachment_metadata/i18n/ru.po → attachment_base_synchronize/i18n/ru.po

0
attachment_metadata/i18n/sl.po → attachment_base_synchronize/i18n/sl.po

0
attachment_metadata/i18n/tr.po → attachment_base_synchronize/i18n/tr.po

0
attachment_metadata/i18n/zh_CN.po → attachment_base_synchronize/i18n/zh_CN.po

0
attachment_metadata/models/__init__.py → attachment_base_synchronize/models/__init__.py

104
attachment_base_synchronize/models/attachment.py

@ -0,0 +1,104 @@
# coding: utf-8
# @ 2015 Florian DA COSTA @ 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
from openerp import sql_db
import hashlib
from base64 import b64decode
import logging
_logger = logging.getLogger(__name__)
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=[],
string="File type",
help="The file type determines an import method to be used "
"to parse and transform data before their import in ERP or an export")
sync_date = fields.Datetime()
state = fields.Selection([
('pending', 'Pending'),
('failed', 'Failed'),
('done', 'Done'),
], readonly=False, required=True, default='pending')
state_message = fields.Text()
@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."))
@api.model
def run_attachment_metadata_scheduler(self, domain=None):
if domain is None:
domain = []
domain.append(('state', '=', 'pending'))
attachments = self.search(domain)
if attachments:
return attachments.run()
return True
@api.multi
def run(self):
"""
Run the process for each attachment metadata
"""
for attachment in self:
new_cr = sql_db.db_connect(self.env.cr.dbname).cursor()
with api.Environment.manage():
attachment.env = api.Environment(new_cr, self.env.uid,
self.env.context)
try:
attachment._run()
except Exception, e:
attachment.env.cr.rollback()
_logger.exception(e)
attachment.write(
{
'state': 'failed',
'state_message': unicode(e)
})
attachment.env.cr.commit()
else:
attachment.write({'state': 'done'})
attachment.env.cr.commit()
finally:
attachment.env.cr.close()
return True
@api.multi
def _run(self):
self.ensure_one()
_logger.info('Start to process attachment metadata id %s' % self.id)
@api.multi
def set_done(self):
"""
Manually set to done
"""
message = "Manually set to done by %s" % self.env.user.name
self.write({'state_message': message, 'state': 'done'})

0
attachment_metadata/security/ir.model.access.csv → attachment_base_synchronize/security/ir.model.access.csv

24
attachment_metadata/views/attachment_view.xml → attachment_base_synchronize/views/attachment_view.xml

@ -6,11 +6,26 @@
<field name="model">ir.attachment.metadata</field>
<field name="inherit_id" ref="base.view_attachment_form" />
<field name="arch" type="xml">
<xpath expr="/form/*" position="before">
<header>
<button name="run" states="pending,failed"
string="Run" type="object" class="oe_highlight"/>
<button name="set_done" states="pending,failed"
string="Set to Done" type="object"/>
</header>
</xpath>
<field name="url" position="after">
<field name="sync_date"/>
<field name="state"/>
<field name="internal_hash"/>
<field name="external_hash"/>
<field name="file_type"/>
</field>
<group name="description_group">
<group name="state_message" string="Error" colspan="4">
<field name="state_message" nolabel="1"/>
</group>
</group>
</field>
</record>
@ -21,6 +36,9 @@
<field name="name"/>
<field name="datas_fname"/>
<field name="file_type"/>
<field name="type"/>
<field name="create_date"/>
<field name="state"/>
</tree>
</field>
</record>
@ -45,11 +63,15 @@
help="Filter on my documents"/>
<field name="create_uid"/>
<field name="type"/>
<filter string="Pending" domain="[('state', '=', 'pending')]"/>
<filter string="Failed" domain="[('state', '=', 'failed')]"/>
<filter string="Done" domain="[('state', '=', 'done')]"/>
<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="Creation Month" name="creation_month" icon="terp-go-month" domain="[]" context="{'group_by':'create_date'}"/>
<filter string="State" domain="[]" context="{'group_by': 'state'}"/>
<filter string="File type" domain="[]" context="{'group_by': 'file_type'}"/>
</group>
</search>

51
attachment_metadata/models/attachment.py

@ -1,51 +0,0 @@
# 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')]
Loading…
Cancel
Save