diff --git a/external_file_location/__openerp__.py b/external_file_location/__openerp__.py
index 57c4ba35..04c1063f 100644
--- a/external_file_location/__openerp__.py
+++ b/external_file_location/__openerp__.py
@@ -32,6 +32,7 @@
""",
'depends': [
'base',
+ 'ir_attachment_metadata',
],
'data': [
'attachment_view.xml',
diff --git a/external_file_location/abstract_task.py b/external_file_location/abstract_task.py
index 13eae0cc..c9397318 100755
--- a/external_file_location/abstract_task.py
+++ b/external_file_location/abstract_task.py
@@ -13,7 +13,8 @@ class AbstractTask(object):
'datas': b64encode(data),
'datas_fname': filename,
'task_id': self.task.id,
- 'location_id': self.task.location_id.id
+ 'location_id': self.task.location_id.id,
+ 'external_hash': self.ext_hash
}
)
return ir_attachment_id
diff --git a/external_file_location/attachment_view.xml b/external_file_location/attachment_view.xml
index 640b4819..d545c346 100644
--- a/external_file_location/attachment_view.xml
+++ b/external_file_location/attachment_view.xml
@@ -25,8 +25,6 @@
-
-
diff --git a/external_file_location/task.py b/external_file_location/task.py
index af190eba..f40bdb34 100644
--- a/external_file_location/task.py
+++ b/external_file_location/task.py
@@ -36,6 +36,9 @@ class Task(models.Model):
location_id = fields.Many2one('external.file.location', string='Location')
attachment_ids = fields.One2many('ir.attachment', 'task_id',
string='Attachment')
+ delete_file = fields.Boolean(string='Delete file')
+ move_file = fields.Boolean(string='Move file')
+ move_path = fields.Char(string='Move path')
def _get_method(self):
res = []
@@ -69,6 +72,9 @@ class Task(models.Model):
'path': self.filepath,
'attachment_ids': self.attachment_ids,
'task': self,
+ 'move_path': self.move_path,
+ 'delete_file': self.delete_file,
+ 'move_file': self.move_file,
}
conn = method_class(self.env, config)
conn.run()
diff --git a/external_file_location/task_view.xml b/external_file_location/task_view.xml
index 08e3bdfe..9a53b833 100644
--- a/external_file_location/task_view.xml
+++ b/external_file_location/task_view.xml
@@ -16,6 +16,9 @@
+
+
+
@@ -33,6 +36,7 @@
+
diff --git a/external_file_location/tasks/ftp.py b/external_file_location/tasks/ftp.py
index c75302eb..218acc3e 100644
--- a/external_file_location/tasks/ftp.py
+++ b/external_file_location/tasks/ftp.py
@@ -25,6 +25,8 @@ import ftputil
import ftputil.session
from ftputil.error import FTPIOError
import logging
+from base64 import b64encode
+import hashlib
_logger = logging.getLogger(__name__)
@@ -44,9 +46,11 @@ class FtpTask(AbstractTask):
self.file_name = config.get('file_name', '')
self.path = config.get('path', '.')
self.move_path = config.get('move_path', '')
+ self.move_file = config.get('move_file', False)
self.delete_file = config.get('delete_file', False)
self.attachment_ids = config.get('attachment_ids', False)
self.task = config.get('task', False)
+ self.ext_hash = False
class FtpImportTask(FtpTask):
@@ -85,6 +89,11 @@ class FtpImportTask(FtpTask):
_logger.info('Deleting file %s' % source)
ftp_conn.remove(source)
+ @staticmethod
+ def _get_hash(file_name, ftp_conn):
+ with ftp_conn.open(file_name, 'rb') as f:
+ return hashlib.md5(f.read()).hexdigest()
+
def run(self):
port_session_factory = ftputil.session.session_factory(
port=self.port)
@@ -99,6 +108,7 @@ class FtpImportTask(FtpTask):
source_name = self._source_name(path, self.file_name)
if ftp_conn.path.isfile(source_name) and \
ftpfile == self.file_name:
+ self.ext_hash = self._get_hash(source_name, ftp_conn)
self._handle_new_source(
ftp_conn,
path,
@@ -110,7 +120,7 @@ class FtpImportTask(FtpTask):
if self.delete_file:
for ftpfile in downloaded_files:
self._delete_file(ftp_conn,
- self._source_name(self.path,
+ self._source_name(path,
ftpfile))
elif self.move_path:
if not ftp_conn.path.exists(self.move_path):
@@ -118,7 +128,7 @@ class FtpImportTask(FtpTask):
for ftpfile in downloaded_files:
self._move_file(
ftp_conn,
- self._source_name(self.path, ftpfile),
+ self._source_name(path, ftpfile),
self._source_name(self.move_path, ftpfile))
diff --git a/ir_attachment_metadata/attachment.py b/ir_attachment_metadata/attachment.py
index fb38f174..3944ee02 100644
--- a/ir_attachment_metadata/attachment.py
+++ b/ir_attachment_metadata/attachment.py
@@ -23,6 +23,7 @@
from openerp import models, fields, api, _
from openerp.exceptions import Warning
import hashlib
+from base64 import b64decode
class IrAttachment(models.Model):
@@ -34,7 +35,7 @@ class IrAttachment(models.Model):
@api.depends('datas', 'external_hash')
def _compute_hash(self):
if self.datas:
- self.internal_hash = hashlib.md5(self.datas).hexdigest()
+ self.internal_hash = hashlib.md5(b64decode(self.datas)).hexdigest()
if self.external_hash and self.internal_hash != self.external_hash:
raise Warning(_('File corrupted'),
_("Something was wrong with the retreived file, "