From 77fb6956dcf7b6675fd383876e788ec9437aeef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Fri, 23 Oct 2020 16:23:29 +0200 Subject: [PATCH] [REF] refactor code, rename enabled to active, and simplifie run code --- .../models/attachment_synchronize_task.py | 18 ++++++++----- attachment_synchronize/tests/test_import.py | 2 +- .../attachment_synchronize_task_views.xml | 26 +++++++++---------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/attachment_synchronize/models/attachment_synchronize_task.py b/attachment_synchronize/models/attachment_synchronize_task.py index 436c79a6a..25688717e 100644 --- a/attachment_synchronize/models/attachment_synchronize_task.py +++ b/attachment_synchronize/models/attachment_synchronize_task.py @@ -89,7 +89,7 @@ class AttachmentSynchronizeTask(models.Model): "\nFurther operations will be realized on these Attachments Queues depending " "on their 'File Type' value.", ) - enabled = fields.Boolean("Enabled", default=True) + active = fields.Boolean("Enabled", default=True, old="enabled") avoid_duplicated_files = fields.Boolean( string="Avoid importing duplicated files", help="If checked, a file will not be imported if an Attachment Queue with the " @@ -139,11 +139,19 @@ class AttachmentSynchronizeTask(models.Model): if domain is None: domain = [] domain = expression.AND( - [domain, [("method_type", "=", "import"), ("enabled", "=", True)]] + [domain, [("method_type", "=", "import")]] ) for task in self.search(domain): task.run_import() + def run(self): + for record in self: + method = "run_{}".format(record.method_type) + if not hasattr(self, method): + raise NotImplemented + else: + getattr(record, method)() + def run_import(self): self.ensure_one() attach_obj = self.env["attachment.queue"] @@ -200,10 +208,6 @@ class AttachmentSynchronizeTask(models.Model): for task in self: task.attachment_ids.filtered(lambda a: a.state == "pending").run() - def button_toogle_enabled(self): - for rec in self: - rec.enabled = not rec.enabled - def button_duplicate_record(self): self.ensure_one() - self.copy({"enabled": False}) + self.copy({"active": False}) diff --git a/attachment_synchronize/tests/test_import.py b/attachment_synchronize/tests/test_import.py index 611555763..a8b0031fc 100644 --- a/attachment_synchronize/tests/test_import.py +++ b/attachment_synchronize/tests/test_import.py @@ -78,6 +78,6 @@ class TestImport(SyncCommon): self._check_attachment_created(count=1) def test_running_cron_disable_task(self): - self.task.write({"after_import": "delete", "enabled": False}) + self.task.write({"after_import": "delete", "active": False}) self.env["attachment.synchronize.task"].run_task_import_scheduler() self._check_attachment_created(count=0) diff --git a/attachment_synchronize/views/attachment_synchronize_task_views.xml b/attachment_synchronize/views/attachment_synchronize_task_views.xml index 7fe1d7999..18f4a2dbc 100644 --- a/attachment_synchronize/views/attachment_synchronize_task_views.xml +++ b/attachment_synchronize/views/attachment_synchronize_task_views.xml @@ -5,16 +5,13 @@
-
-
-
-