Skip to content

Commit

Permalink
[ADD] queue_job_web_notify - allow to notify in cas of success
Browse files Browse the repository at this point in the history
  • Loading branch information
baimont committed Jan 23, 2025
1 parent 2413ef6 commit 64c3481
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 5 deletions.
4 changes: 2 additions & 2 deletions queue_job_web_notify/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Queue Job Web Notify
====================

..
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
Expand All @@ -29,7 +29,7 @@ Queue Job Web Notify
|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the mail notification feature of Queue Job. It adds
the possibility to enable the web notification of failed jobs. When
the possibility to enable the web notification of failed or done jobs. When
enabled, the user will be notified by a web notification. The web
notification is a pop-up message that appears in the user's browser.

Expand Down
20 changes: 19 additions & 1 deletion queue_job_web_notify/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-04 13:47+0000\n"
"POT-Creation-Date: 2025-01-23 14:54+0000\n"
"PO-Revision-Date: 2024-03-04 13:47+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
Expand All @@ -22,18 +22,36 @@ msgid "Display a notification in the user interface when the job fails."
msgstr ""
"Affiche une notification dans l'interface utilisateur lorsque le job échoue."

#. module: queue_job_web_notify
#: model:ir.model.fields,help:queue_job_web_notify.field_queue_job_function__is_web_notify_done_enabled
msgid "Display a notification in the user interface when the job is done."
msgstr ""
"Affiche une notification dans l'interface utilisateur lorsque le job réussit."

#. module: queue_job_web_notify
#: model:ir.model,name:queue_job_web_notify.model_queue_job_function
msgid "Job Functions"
msgstr ""

#. module: queue_job_web_notify
#. odoo-python
#: code:addons/queue_job_web_notify/models/queue_job.py:0
#, python-format
msgid "Job done"
msgstr "Job réussi"

#. module: queue_job_web_notify
#. odoo-python
#: code:addons/queue_job_web_notify/models/queue_job.py:0
#, python-format
msgid "Job failed"
msgstr "Job échoué"

#. module: queue_job_web_notify
#: model:ir.model.fields,field_description:queue_job_web_notify.field_queue_job_function__is_web_notify_done_enabled
msgid "Notify on done"
msgstr "Notifier en cas de réussite"

#. module: queue_job_web_notify
#: model:ir.model.fields,field_description:queue_job_web_notify.field_queue_job_function__is_web_notify_failure_enabled
msgid "Notify on failure"
Expand Down
21 changes: 20 additions & 1 deletion queue_job_web_notify/i18n/queue_job_web_notify.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Project-Id-Version: Odoo Server 16.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-23 14:54+0000\n"
"PO-Revision-Date: 2025-01-23 14:54+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand All @@ -18,18 +20,35 @@ msgstr ""
msgid "Display a notification in the user interface when the job fails."
msgstr ""

#. module: queue_job_web_notify
#: model:ir.model.fields,help:queue_job_web_notify.field_queue_job_function__is_web_notify_done_enabled
msgid "Display a notification in the user interface when the job is done."
msgstr ""

#. module: queue_job_web_notify
#: model:ir.model,name:queue_job_web_notify.model_queue_job_function
msgid "Job Functions"
msgstr ""

#. module: queue_job_web_notify
#. odoo-python
#: code:addons/queue_job_web_notify/models/queue_job.py:0
#, python-format
msgid "Job done"
msgstr ""

#. module: queue_job_web_notify
#. odoo-python
#: code:addons/queue_job_web_notify/models/queue_job.py:0
#, python-format
msgid "Job failed"
msgstr ""

#. module: queue_job_web_notify
#: model:ir.model.fields,field_description:queue_job_web_notify.field_queue_job_function__is_web_notify_done_enabled
msgid "Notify on done"
msgstr ""

#. module: queue_job_web_notify
#: model:ir.model.fields,field_description:queue_job_web_notify.field_queue_job_function__is_web_notify_failure_enabled
msgid "Notify on failure"
Expand Down
25 changes: 25 additions & 0 deletions queue_job_web_notify/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, models
from odoo.addons.queue_job.job import DONE


class QueueJob(models.Model):
Expand All @@ -11,10 +12,18 @@ def _get_web_notify_failure_title(self):
self.ensure_one()
return _("Job failed")

def _get_web_notify_done_title(self):
self.ensure_one()
return _("Job done")

Check warning on line 17 in queue_job_web_notify/models/queue_job.py

View check run for this annotation

Codecov / codecov/patch

queue_job_web_notify/models/queue_job.py#L16-L17

Added lines #L16 - L17 were not covered by tests

def _get_web_notify_failure_message(self):
self.ensure_one()
return self.display_name

def _get_web_notify_done_message(self):
self.ensure_one()
return self.display_name

Check warning on line 25 in queue_job_web_notify/models/queue_job.py

View check run for this annotation

Codecov / codecov/patch

queue_job_web_notify/models/queue_job.py#L24-L25

Added lines #L24 - L25 were not covered by tests

def _message_post_on_failure(self):
res = super()._message_post_on_failure()
for job in self:
Expand All @@ -26,3 +35,19 @@ def _message_post_on_failure(self):
message=notification_message, title=notification_title, sticky=True
)
return res

def _message_post_on_done(self):
for job in self:
if not job.job_function_id.is_web_notify_done_enabled:
continue
notification_title = job._get_web_notify_done_title()
notification_message = job._get_web_notify_done_message()
job.user_id.notify_success(

Check warning on line 45 in queue_job_web_notify/models/queue_job.py

View check run for this annotation

Codecov / codecov/patch

queue_job_web_notify/models/queue_job.py#L43-L45

Added lines #L43 - L45 were not covered by tests
message=notification_message, title=notification_title, sticky=True
)

def write(self, vals):
result = super().write(vals)
if vals.get("state") == "done":
self._message_post_on_done()
return result
5 changes: 5 additions & 0 deletions queue_job_web_notify/models/queue_job_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ class QueueJobFunction(models.Model):
help="Display a notification in the user interface when the job fails.",
default=False,
)
is_web_notify_done_enabled = fields.Boolean(
string="Notify on done",
help="Display a notification in the user interface when the job is done.",
default=False,
)
2 changes: 1 addition & 1 deletion queue_job_web_notify/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This module extends the mail notification feature of Queue Job. It adds the possibility
to enable the web notification of failed jobs. When enabled, the user will be notified
to enable the web notification of failed or done jobs. When enabled, the user will be notified
by a web notification. The web notification is a pop-up message that appears in the
user's browser.
1 change: 1 addition & 0 deletions queue_job_web_notify/views/queue_job_function.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<xpath expr="//field[@name='name']/.." position="after">
<group name="group_web_notify">
<field name="is_web_notify_failure_enabled" />
<field name="is_web_notify_done_enabled" />
</group>
</xpath>
</field>
Expand Down

0 comments on commit 64c3481

Please sign in to comment.