Skip to content

[ADD] queue_job_web_notify - allow to notify in case of success #741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 24 additions & 0 deletions queue_job_web_notify/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@
self.ensure_one()
return _("Job failed")

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

Check warning on line 16 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#L15-L16

Added lines #L15 - L16 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 24 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#L23-L24

Added lines #L23 - L24 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 +34,19 @@
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 44 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#L42-L44

Added lines #L42 - L44 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
Loading