diff --git a/external_file_location/abstract_task.py b/external_file_location/abstract_task.py
index 322f0062..13eae0cc 100755
--- a/external_file_location/abstract_task.py
+++ b/external_file_location/abstract_task.py
@@ -11,13 +11,9 @@ class AbstractTask(object):
{
'name': filename,
'datas': b64encode(data),
- 'datas_fname': filename
+ 'datas_fname': filename,
+ 'task_id': self.task.id,
+ 'location_id': self.task.location_id.id
}
)
return ir_attachment_id
-
- # def load_file(self, file_id):
- # f = self.session.browse('impexp.file', file_id)
- # if not f.attachment_id.datas:
- # return None
- # return b64decode(f.attachment_id.datas)
diff --git a/external_file_location/attachment.py b/external_file_location/attachment.py
index 30b8e335..410da1db 100644
--- a/external_file_location/attachment.py
+++ b/external_file_location/attachment.py
@@ -31,7 +31,7 @@ class IrAttachment(models.Model):
('pending', 'Pending'),
('failed', 'Failed'),
('done', 'Done'),
- ], readonly=True, required=True, default='pending')
+ ], readonly=False, required=True, default='pending')
state_message = fields.Text()
task_id = fields.Many2one('external.file.task', string='Task')
location_id = fields.Many2one('external.file.location', string='Location',
diff --git a/external_file_location/task.py b/external_file_location/task.py
index 948e4772..af190eba 100644
--- a/external_file_location/task.py
+++ b/external_file_location/task.py
@@ -67,7 +67,8 @@ class Task(models.Model):
'allow_dir_creation': False,
'file_name': self.filename,
'path': self.filepath,
- 'attachment_id': self.attachment_id,
+ 'attachment_ids': self.attachment_ids,
+ 'task': self,
}
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 caf1dc7f..9e907e92 100644
--- a/external_file_location/task_view.xml
+++ b/external_file_location/task_view.xml
@@ -13,7 +13,8 @@
-
+
+
diff --git a/external_file_location/tasks/ftp.py b/external_file_location/tasks/ftp.py
index 5bbeaf49..c75302eb 100644
--- a/external_file_location/tasks/ftp.py
+++ b/external_file_location/tasks/ftp.py
@@ -42,10 +42,11 @@ class FtpTask(AbstractTask):
self.port = config.get('port', '')
self.allow_dir_creation = config.get('allow_dir_creation', '')
self.file_name = config.get('file_name', '')
- self.path = config.get('path', './')
+ self.path = config.get('path', '.')
self.move_path = config.get('move_path', '')
self.delete_file = config.get('delete_file', False)
- self.attachment_id = config.get('attachment_id', False)
+ self.attachment_ids = config.get('attachment_ids', False)
+ self.task = config.get('task', False)
class FtpImportTask(FtpTask):
@@ -91,15 +92,16 @@ class FtpImportTask(FtpTask):
self.pwd,
session_factory=port_session_factory) as ftp_conn:
- file_list = ftp_conn.listdir(self.path)
+ path = self.path or '.'
+ file_list = ftp_conn.listdir(path)
downloaded_files = []
for ftpfile in file_list:
- source_name = self._source_name(self.path, self.file_name)
+ source_name = self._source_name(path, self.file_name)
if ftp_conn.path.isfile(source_name) and \
ftpfile == self.file_name:
self._handle_new_source(
ftp_conn,
- self.path,
+ path,
self.file_name,
self.move_path)
downloaded_files.append(self.file_name)
@@ -148,7 +150,7 @@ class FtpExportTask(FtpTask):
return upload_directory + '/' + filename
def _upload_file(self, host, port, user, pwd, path, filename, filedata):
- upload_directory = path or './'
+ upload_directory = path or '.'
port_session_factory = ftputil.session.session_factory(port=port)
with ftputil.FTPHost(host, user, pwd,
session_factory=port_session_factory) as ftp_conn:
@@ -161,6 +163,10 @@ class FtpExportTask(FtpTask):
self._handle_new_target(ftp_conn, target_name, filedata)
def run(self, async=True):
- self._upload_file(self.host, self.port, self.user, self.pwd, self.path,
- self.attachment_id.datas_fname,
- b64decode(self.attachment_id.datas))
+ for attachment in self.attachment_ids:
+ if attachment.state in ('pending', 'failed'):
+ self.attachment_id = attachment
+ self._upload_file(self.host, self.port, self.user, self.pwd,
+ self.path,
+ attachment.datas_fname,
+ b64decode(attachment.datas))