diff --git a/attachment_synchronize/__manifest__.py b/attachment_synchronize/__manifest__.py index f1d86490b..62db290b0 100644 --- a/attachment_synchronize/__manifest__.py +++ b/attachment_synchronize/__manifest__.py @@ -12,9 +12,9 @@ "category": "Generic Modules", "depends": ["attachment_queue", "storage_backend"], "data": [ - "views/attachment_view.xml", - "views/task_view.xml", - "views/storage_backend_view.xml", + "views/attachment_queue_views.xml", + "views/attachment_synchronize_task_views.xml", + "views/storage_backend_views.xml", "data/cron.xml", "security/ir.model.access.csv", ], diff --git a/attachment_synchronize/models/__init__.py b/attachment_synchronize/models/__init__.py index 9c2603f17..afcda8bde 100644 --- a/attachment_synchronize/models/__init__.py +++ b/attachment_synchronize/models/__init__.py @@ -1,3 +1 @@ -from . import attachment -from . import task -from . import storage_backend +from . import attachment_queue, attachment_synchronize_task, storage_backend diff --git a/attachment_synchronize/models/attachment.py b/attachment_synchronize/models/attachment_queue.py similarity index 100% rename from attachment_synchronize/models/attachment.py rename to attachment_synchronize/models/attachment_queue.py diff --git a/attachment_synchronize/models/task.py b/attachment_synchronize/models/attachment_synchronize_task.py similarity index 83% rename from attachment_synchronize/models/task.py rename to attachment_synchronize/models/attachment_synchronize_task.py index eff4d252f..5d9239938 100644 --- a/attachment_synchronize/models/task.py +++ b/attachment_synchronize/models/attachment_synchronize_task.py @@ -59,13 +59,11 @@ class AttachmentSynchronizeTask(models.Model): "least contains the pattern in its name. " "Leave it empty to import all files" ) - filepath = fields.Char(help="Path to imported/exported files in the Backend") - backend_id = fields.Many2one( - "storage.backend", string="Backend", required=True - ) - attachment_ids = fields.One2many( - "attachment.queue", "task_id", string="Attachment" + filepath = fields.Char( + string="File Path", help="Path to imported/exported files in the Backend" ) + backend_id = fields.Many2one("storage.backend", string="Backend") + attachment_ids = fields.One2many("attachment.queue", "task_id", string="Attachment") move_path = fields.Char( string="Move Path", help="Imported File will be moved to this path" ) @@ -102,6 +100,10 @@ class AttachmentSynchronizeTask(models.Model): "when excuting the files linked to this task", ) + def toogle_enabled(self): + for task in self: + task.enabled = not task.enabled + def _prepare_attachment_vals(self, data, filename): self.ensure_one() vals = { @@ -125,8 +127,7 @@ class AttachmentSynchronizeTask(models.Model): render_result = template.render(variables) except Exception: _logger.exception( - "Failed to render template %r using values %r" - % (template, variables) + "Failed to render template %r using values %r" % (template, variables) ) render_result = u"" if render_result == u"False": @@ -155,35 +156,21 @@ class AttachmentSynchronizeTask(models.Model): for file_name in filenames: with api.Environment.manage(): with odoo.registry(self.env.cr.dbname).cursor() as new_cr: - new_env = api.Environment( - new_cr, self.env.uid, self.env.context - ) + new_env = api.Environment(new_cr, self.env.uid, self.env.context) try: full_absolute_path = os.path.join(filepath, file_name) data = backend._get_b64_data(full_absolute_path) - attach_vals = self._prepare_attachment_vals( - data, file_name - ) - attachment = attach_obj.with_env(new_env).create( - attach_vals - ) + attach_vals = self._prepare_attachment_vals(data, file_name) + attachment = attach_obj.with_env(new_env).create(attach_vals) new_full_path = False if self.after_import == "rename": - new_name = self._template_render( - self.new_name, attachment - ) + new_name = self._template_render(self.new_name, attachment) new_full_path = os.path.join(filepath, new_name) elif self.after_import == "move": - new_full_path = os.path.join( - self.move_path, file_name - ) + new_full_path = os.path.join(self.move_path, file_name) elif self.after_import == "move_rename": - new_name = self._template_render( - self.new_name, attachment - ) - new_full_path = os.path.join( - self.move_path, new_name - ) + new_name = self._template_render(self.new_name, attachment) + new_full_path = os.path.join(self.move_path, new_name) if new_full_path: backend._add_b64_data(new_full_path, data) if self.after_import in ( @@ -199,9 +186,7 @@ class AttachmentSynchronizeTask(models.Model): raise e else: new_env.cr.commit() - _logger.info( - "Run import complete! Imported {0} files".format(total_import) - ) + _logger.info("Run import complete! Imported {0} files".format(total_import)) def _file_to_import(self, filenames): imported = ( diff --git a/attachment_synchronize/views/attachment_view.xml b/attachment_synchronize/views/attachment_queue_views.xml similarity index 100% rename from attachment_synchronize/views/attachment_view.xml rename to attachment_synchronize/views/attachment_queue_views.xml diff --git a/attachment_synchronize/views/task_view.xml b/attachment_synchronize/views/attachment_synchronize_task_views.xml similarity index 59% rename from attachment_synchronize/views/task_view.xml rename to attachment_synchronize/views/attachment_synchronize_task_views.xml index 93461cca2..4ca32bbc1 100644 --- a/attachment_synchronize/views/task_view.xml +++ b/attachment_synchronize/views/attachment_synchronize_task_views.xml @@ -5,9 +5,23 @@
-
+
+ +
- + + - - - +
@@ -45,7 +58,6 @@ - @@ -69,33 +81,67 @@ - - Attachments Tasks + + + + Attachments Import Tasks ir.actions.act_window attachment.synchronize.task form tree,form + [('method_type', '=', 'import')] tree - + form - + - + action="action_attachment_import_task"/> + + + + Attachments Export Tasks + ir.actions.act_window + attachment.synchronize.task + form + tree,form + + + [('method_type', '=', 'export')] + + + + + tree + + + + + + + form + + + + + diff --git a/attachment_synchronize/views/storage_backend_view.xml b/attachment_synchronize/views/storage_backend_views.xml similarity index 100% rename from attachment_synchronize/views/storage_backend_view.xml rename to attachment_synchronize/views/storage_backend_views.xml