diff --git a/external_file_location/attachment.py b/external_file_location/attachment.py
index cb23810d..33e55086 100644
--- a/external_file_location/attachment.py
+++ b/external_file_location/attachment.py
@@ -27,8 +27,9 @@ class IrAttachment(models.Model):
_inherit = 'ir.attachment'
sync_date = fields.Datetime()
- parse_state = fields.Selection([
+ state = fields.Selection([
('pending', 'Pending'),
('failed', 'Failed'),
('done', 'Done'),
], readonly=True, required=True, default='pending')
+ state_message = fields.Text()
diff --git a/external_file_location/attachment_view.xml b/external_file_location/attachment_view.xml
index 69cd719e..73f833e1 100644
--- a/external_file_location/attachment_view.xml
+++ b/external_file_location/attachment_view.xml
@@ -8,11 +8,50 @@
-
+
+
+
+ ir.attachment
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Attachments
+ ir.actions.act_window
+ ir.attachment
+ form
+ kanban,tree,form
+
+
+
+
+
+ tree
+
+
+
+
+
+
diff --git a/external_file_location/location.py b/external_file_location/location.py
index 07555b68..8d26e462 100644
--- a/external_file_location/location.py
+++ b/external_file_location/location.py
@@ -34,6 +34,7 @@ class Location(models.Model):
port = fields.Integer()
login = fields.Char()
password = fields.Char()
+ task_ids = fields.One2many('external.file.task', 'location_id')
def _get_protocol(self):
diff --git a/external_file_location/location_view.xml b/external_file_location/location_view.xml
index c3fed2ce..7136a2f5 100644
--- a/external_file_location/location_view.xml
+++ b/external_file_location/location_view.xml
@@ -14,7 +14,17 @@
-
+
+
+
+
+
+
+
+
+
+
+
@@ -28,9 +38,7 @@
-
-
diff --git a/external_file_location/task.py b/external_file_location/task.py
index d6352298..70759aab 100644
--- a/external_file_location/task.py
+++ b/external_file_location/task.py
@@ -26,7 +26,7 @@ from abstract_task import AbstractTask
class Task(models.Model):
- _name = 'ir.location.task'
+ _name = 'external.file.task'
_description = 'Description'
name = fields.Char()
diff --git a/external_file_location/task_view.xml b/external_file_location/task_view.xml
index f0e54343..284b63fe 100644
--- a/external_file_location/task_view.xml
+++ b/external_file_location/task_view.xml
@@ -3,7 +3,7 @@
- ir.location.task
+ external.file.task
- ir.location.task
+ external.file.task
@@ -36,12 +36,12 @@
Tasks
ir.actions.act_window
- ir.location.task
+ external.file.task
form
-
diff --git a/external_file_location/tasks/ftp.py b/external_file_location/tasks/ftp.py
index f7b266c9..6992aba6 100644
--- a/external_file_location/tasks/ftp.py
+++ b/external_file_location/tasks/ftp.py
@@ -23,6 +23,7 @@ from ..abstract_task import AbstractTask
from base64 import b64decode
import ftputil
import ftputil.session
+from ftputil.error import FTPIOError
import logging
_logger = logging.getLogger(__name__)
@@ -132,16 +133,21 @@ class FtpExportTask(FtpTask):
raise Exception("%s already exists" % target_name)
def _handle_new_target(self, ftp_conn, target_name, filedata):
- with ftp_conn.open(target_name, mode='wb') as fileobj:
- fileobj.write(filedata)
- _logger.info('wrote %s, size %d', target_name, len(filedata))
- # return file_id
+ try:
+ with ftp_conn.open(target_name, mode='wb') as fileobj:
+ fileobj.write(filedata)
+ _logger.info('wrote %s, size %d', target_name, len(filedata))
+ self.attachment_id.state = 'done'
+ except FTPIOError:
+ self.attachment_id.state = 'failed'
+ self.attachment_id.state_message = (
+ 'The directory doesn\'t exist or had insufficient rights')
def _target_name(self, ftp_conn, upload_directory, filename):
return upload_directory + '/' + filename
def _upload_file(self, host, port, user, pwd, path, filename, filedata):
- upload_directory = path
+ 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: