diff --git a/attachment_metadata/README.rst b/attachment_base_synchronize/README.rst
similarity index 100%
rename from attachment_metadata/README.rst
rename to attachment_base_synchronize/README.rst
diff --git a/attachment_metadata/__init__.py b/attachment_base_synchronize/__init__.py
similarity index 100%
rename from attachment_metadata/__init__.py
rename to attachment_base_synchronize/__init__.py
diff --git a/attachment_metadata/__openerp__.py b/attachment_base_synchronize/__openerp__.py
similarity index 74%
rename from attachment_metadata/__openerp__.py
rename to attachment_base_synchronize/__openerp__.py
index 23b3d6795..1e5c38119 100644
--- a/attachment_metadata/__openerp__.py
+++ b/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,
diff --git a/attachment_base_synchronize/data/cron.xml b/attachment_base_synchronize/data/cron.xml
new file mode 100644
index 000000000..031d594dc
--- /dev/null
+++ b/attachment_base_synchronize/data/cron.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+ Run Attachments Metadata
+ 30
+ minutes
+ -1
+ False
+
+ ir.attachment.metadata
+ run_attachment_metadata_scheduler
+ ([])
+
+
+
+
diff --git a/attachment_metadata/i18n/de.po b/attachment_base_synchronize/i18n/de.po
similarity index 100%
rename from attachment_metadata/i18n/de.po
rename to attachment_base_synchronize/i18n/de.po
diff --git a/attachment_metadata/i18n/en.po b/attachment_base_synchronize/i18n/en.po
similarity index 100%
rename from attachment_metadata/i18n/en.po
rename to attachment_base_synchronize/i18n/en.po
diff --git a/attachment_metadata/i18n/es.po b/attachment_base_synchronize/i18n/es.po
similarity index 100%
rename from attachment_metadata/i18n/es.po
rename to attachment_base_synchronize/i18n/es.po
diff --git a/attachment_metadata/i18n/fi.po b/attachment_base_synchronize/i18n/fi.po
similarity index 100%
rename from attachment_metadata/i18n/fi.po
rename to attachment_base_synchronize/i18n/fi.po
diff --git a/attachment_metadata/i18n/fr.po b/attachment_base_synchronize/i18n/fr.po
similarity index 100%
rename from attachment_metadata/i18n/fr.po
rename to attachment_base_synchronize/i18n/fr.po
diff --git a/attachment_metadata/i18n/it.po b/attachment_base_synchronize/i18n/it.po
similarity index 98%
rename from attachment_metadata/i18n/it.po
rename to attachment_base_synchronize/i18n/it.po
index f85fc0522..8cb84d908 100644
--- a/attachment_metadata/i18n/it.po
+++ b/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
diff --git a/attachment_metadata/i18n/pt_BR.po b/attachment_base_synchronize/i18n/pt_BR.po
similarity index 100%
rename from attachment_metadata/i18n/pt_BR.po
rename to attachment_base_synchronize/i18n/pt_BR.po
diff --git a/attachment_metadata/i18n/ru.po b/attachment_base_synchronize/i18n/ru.po
similarity index 100%
rename from attachment_metadata/i18n/ru.po
rename to attachment_base_synchronize/i18n/ru.po
diff --git a/attachment_metadata/i18n/sl.po b/attachment_base_synchronize/i18n/sl.po
similarity index 100%
rename from attachment_metadata/i18n/sl.po
rename to attachment_base_synchronize/i18n/sl.po
diff --git a/attachment_metadata/i18n/tr.po b/attachment_base_synchronize/i18n/tr.po
similarity index 100%
rename from attachment_metadata/i18n/tr.po
rename to attachment_base_synchronize/i18n/tr.po
diff --git a/attachment_metadata/i18n/zh_CN.po b/attachment_base_synchronize/i18n/zh_CN.po
similarity index 100%
rename from attachment_metadata/i18n/zh_CN.po
rename to attachment_base_synchronize/i18n/zh_CN.po
diff --git a/attachment_metadata/models/__init__.py b/attachment_base_synchronize/models/__init__.py
similarity index 100%
rename from attachment_metadata/models/__init__.py
rename to attachment_base_synchronize/models/__init__.py
diff --git a/attachment_base_synchronize/models/attachment.py b/attachment_base_synchronize/models/attachment.py
new file mode 100644
index 000000000..21064e364
--- /dev/null
+++ b/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'})
diff --git a/attachment_metadata/security/ir.model.access.csv b/attachment_base_synchronize/security/ir.model.access.csv
similarity index 100%
rename from attachment_metadata/security/ir.model.access.csv
rename to attachment_base_synchronize/security/ir.model.access.csv
diff --git a/attachment_metadata/views/attachment_view.xml b/attachment_base_synchronize/views/attachment_view.xml
similarity index 74%
rename from attachment_metadata/views/attachment_view.xml
rename to attachment_base_synchronize/views/attachment_view.xml
index 71ed3a2cd..ae73825c5 100644
--- a/attachment_metadata/views/attachment_view.xml
+++ b/attachment_base_synchronize/views/attachment_view.xml
@@ -6,11 +6,26 @@
ir.attachment.metadata
+
+
+
+
+
+
+
+
+
+
@@ -21,6 +36,9 @@
+
+
+
@@ -45,11 +63,15 @@
help="Filter on my documents"/>
+
+
+
-
+
+
diff --git a/attachment_metadata/models/attachment.py b/attachment_metadata/models/attachment.py
deleted file mode 100644
index 6fd9d52b0..000000000
--- a/attachment_metadata/models/attachment.py
+++ /dev/null
@@ -1,51 +0,0 @@
-# coding: utf-8
-# Copyright (C) 2014 initOS GmbH & Co. KG ().
-# @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')]