From 5d5d277e3dd75fc4bae98ccea959ea800bbaeeb9 Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Thu, 4 Mar 2021 12:12:04 +0100 Subject: [PATCH] [IMP] attachment_queue: pre-commit --- attachment_queue/data/cron.xml | 4 +- attachment_queue/data/ir_config_parameter.xml | 2 +- attachment_queue/data/mail_template.xml | 8 +- .../demo/attachment_queue_demo.xml | 2 +- attachment_queue/models/attachment_queue.py | 14 +- attachment_queue/readme/USAGE.rst | 1 - .../tests/test_attachment_queue.py | 10 +- .../views/attachment_queue_view.xml | 153 ++++++++++++------ 8 files changed, 117 insertions(+), 77 deletions(-) diff --git a/attachment_queue/data/cron.xml b/attachment_queue/data/cron.xml index ad4e6540a..fa8130f4b 100644 --- a/attachment_queue/data/cron.xml +++ b/attachment_queue/data/cron.xml @@ -1,4 +1,4 @@ - + @@ -8,7 +8,7 @@ -1 False - + code model.run_attachment_queue_scheduler() diff --git a/attachment_queue/data/ir_config_parameter.xml b/attachment_queue/data/ir_config_parameter.xml index 5b723255a..ecf34bf8c 100644 --- a/attachment_queue/data/ir_config_parameter.xml +++ b/attachment_queue/data/ir_config_parameter.xml @@ -1,4 +1,4 @@ - + attachment_queue_cron_batch_limit diff --git a/attachment_queue/data/mail_template.xml b/attachment_queue/data/mail_template.xml index 4eec88492..ce8d48146 100644 --- a/attachment_queue/data/mail_template.xml +++ b/attachment_queue/data/mail_template.xml @@ -1,12 +1,14 @@ - + ${object.failure_emails} Attachment Failure notification The attachment ${object.name} has failed - - + Hello,

The attachment ${object.name} has failed with the following error message :
${object.state_message}

Regards,

diff --git a/attachment_queue/demo/attachment_queue_demo.xml b/attachment_queue/demo/attachment_queue_demo.xml index ef69be60a..b906a760e 100644 --- a/attachment_queue/demo/attachment_queue_demo.xml +++ b/attachment_queue/demo/attachment_queue_demo.xml @@ -1,4 +1,4 @@ - + diff --git a/attachment_queue/models/attachment_queue.py b/attachment_queue/models/attachment_queue.py index 4c058dac3..e3cf5e58a 100644 --- a/attachment_queue/models/attachment_queue.py +++ b/attachment_queue/models/attachment_queue.py @@ -35,7 +35,7 @@ class AttachmentQueue(models.Model): compute="_compute_failure_emails", string="Failure Emails", help="Comma-separated list of email addresses to be notified in case of" - "failure", + "failure", ) def _compute_failure_emails(self): @@ -67,15 +67,11 @@ class AttachmentQueue(models.Model): """ Run the process for each attachment queue """ - failure_tmpl = self.env.ref( - "attachment_queue.attachment_failure_notification" - ) + failure_tmpl = self.env.ref("attachment_queue.attachment_failure_notification") for attachment in self: with api.Environment.manage(): with 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) attach = attachment.with_env(new_env) try: attach._run() @@ -83,9 +79,7 @@ class AttachmentQueue(models.Model): except Exception as e: attach.env.cr.rollback() _logger.exception(str(e)) - attach.write( - {"state": "failed", "state_message": str(e)} - ) + attach.write({"state": "failed", "state_message": str(e)}) emails = attach.failure_emails if emails: failure_tmpl.send_mail(attach.id) diff --git a/attachment_queue/readme/USAGE.rst b/attachment_queue/readme/USAGE.rst index a97a271e5..bb13e8c9e 100644 --- a/attachment_queue/readme/USAGE.rst +++ b/attachment_queue/readme/USAGE.rst @@ -14,4 +14,3 @@ This module can be used in combination with attachment_synchronize to control fi image:: ../static/description/form.png - diff --git a/attachment_queue/tests/test_attachment_queue.py b/attachment_queue/tests/test_attachment_queue.py index 74d368f2b..3d8910be3 100644 --- a/attachment_queue/tests/test_attachment_queue.py +++ b/attachment_queue/tests/test_attachment_queue.py @@ -12,17 +12,14 @@ class TestAttachmentBaseQueue(TransactionCase): self.env = api.Environment( self.registry.test_cr, self.env.uid, self.env.context ) - self.attachment = self.env.ref( - "attachment_queue.attachment_queue_demo" - ) + self.attachment = self.env.ref("attachment_queue.attachment_queue_demo") def tearDown(self): self.registry.leave_test_mode() super().tearDown() def test_attachment_queue(self): - """Test run_attachment_queue_scheduler to ensure set state to done - """ + """Test run_attachment_queue_scheduler to ensure set state to done""" self.assertEqual(self.attachment.state, "pending") self.env["attachment.queue"].run_attachment_queue_scheduler() self.env.cache.invalidate() @@ -32,8 +29,7 @@ class TestAttachmentBaseQueue(TransactionCase): self.assertEqual(attach.state, "done") def test_set_done(self): - """Test set_done manually - """ + """Test set_done manually""" self.assertEqual(self.attachment.state, "pending") self.attachment.set_done() self.assertEqual(self.attachment.state, "done") diff --git a/attachment_queue/views/attachment_queue_view.xml b/attachment_queue/views/attachment_queue_view.xml index 1f3b1964f..081d420c9 100644 --- a/attachment_queue/views/attachment_queue_view.xml +++ b/attachment_queue/views/attachment_queue_view.xml @@ -1,27 +1,36 @@ - + attachment.queue - + primary
-
- - - + + + - + @@ -31,12 +40,12 @@ attachment.queue - - - - - - + + + + + +
@@ -45,31 +54,69 @@ attachment.queue - - - - - - - - - - - + + + + + + + + + + + - - - - - - + + + + + + @@ -81,27 +128,29 @@ attachment.queue form tree,form - - + +
- + tree - - + + - + form - - + + - +