Skip to content

Commit f5a3dbf

Browse files
committed
[ADD] queue_job_web_notify - allow to notify in cas of success
1 parent 2413ef6 commit f5a3dbf

File tree

7 files changed

+72
-5
lines changed

7 files changed

+72
-5
lines changed

queue_job_web_notify/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Queue Job Web Notify
33
====================
44

5-
..
5+
..
66
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
@@ -29,7 +29,7 @@ Queue Job Web Notify
2929
|badge1| |badge2| |badge3| |badge4| |badge5|
3030

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

queue_job_web_notify/i18n/fr.po

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ msgid ""
66
msgstr ""
77
"Project-Id-Version: Odoo Server 16.0+e\n"
88
"Report-Msgid-Bugs-To: \n"
9-
"POT-Creation-Date: 2024-03-04 13:47+0000\n"
9+
"POT-Creation-Date: 2025-01-23 14:54+0000\n"
1010
"PO-Revision-Date: 2024-03-04 13:47+0000\n"
1111
"Last-Translator: \n"
1212
"Language-Team: \n"
@@ -22,18 +22,36 @@ msgid "Display a notification in the user interface when the job fails."
2222
msgstr ""
2323
"Affiche une notification dans l'interface utilisateur lorsque le job échoue."
2424

25+
#. module: queue_job_web_notify
26+
#: model:ir.model.fields,help:queue_job_web_notify.field_queue_job_function__is_web_notify_done_enabled
27+
msgid "Display a notification in the user interface when the job is done."
28+
msgstr ""
29+
"Affiche une notification dans l'interface utilisateur lorsque le job réussit."
30+
2531
#. module: queue_job_web_notify
2632
#: model:ir.model,name:queue_job_web_notify.model_queue_job_function
2733
msgid "Job Functions"
2834
msgstr ""
2935

36+
#. module: queue_job_web_notify
37+
#. odoo-python
38+
#: code:addons/queue_job_web_notify/models/queue_job.py:0
39+
#, python-format
40+
msgid "Job done"
41+
msgstr "Job réussi"
42+
3043
#. module: queue_job_web_notify
3144
#. odoo-python
3245
#: code:addons/queue_job_web_notify/models/queue_job.py:0
3346
#, python-format
3447
msgid "Job failed"
3548
msgstr "Job échoué"
3649

50+
#. module: queue_job_web_notify
51+
#: model:ir.model.fields,field_description:queue_job_web_notify.field_queue_job_function__is_web_notify_done_enabled
52+
msgid "Notify on done"
53+
msgstr "Notifier en cas de réussite"
54+
3755
#. module: queue_job_web_notify
3856
#: model:ir.model.fields,field_description:queue_job_web_notify.field_queue_job_function__is_web_notify_failure_enabled
3957
msgid "Notify on failure"

queue_job_web_notify/i18n/queue_job_web_notify.pot

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
#
55
msgid ""
66
msgstr ""
7-
"Project-Id-Version: Odoo Server 16.0\n"
7+
"Project-Id-Version: Odoo Server 16.0+e\n"
88
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2025-01-23 14:54+0000\n"
10+
"PO-Revision-Date: 2025-01-23 14:54+0000\n"
911
"Last-Translator: \n"
1012
"Language-Team: \n"
1113
"MIME-Version: 1.0\n"
@@ -18,18 +20,35 @@ msgstr ""
1820
msgid "Display a notification in the user interface when the job fails."
1921
msgstr ""
2022

23+
#. module: queue_job_web_notify
24+
#: model:ir.model.fields,help:queue_job_web_notify.field_queue_job_function__is_web_notify_done_enabled
25+
msgid "Display a notification in the user interface when the job is done."
26+
msgstr ""
27+
2128
#. module: queue_job_web_notify
2229
#: model:ir.model,name:queue_job_web_notify.model_queue_job_function
2330
msgid "Job Functions"
2431
msgstr ""
2532

33+
#. module: queue_job_web_notify
34+
#. odoo-python
35+
#: code:addons/queue_job_web_notify/models/queue_job.py:0
36+
#, python-format
37+
msgid "Job done"
38+
msgstr ""
39+
2640
#. module: queue_job_web_notify
2741
#. odoo-python
2842
#: code:addons/queue_job_web_notify/models/queue_job.py:0
2943
#, python-format
3044
msgid "Job failed"
3145
msgstr ""
3246

47+
#. module: queue_job_web_notify
48+
#: model:ir.model.fields,field_description:queue_job_web_notify.field_queue_job_function__is_web_notify_done_enabled
49+
msgid "Notify on done"
50+
msgstr ""
51+
3352
#. module: queue_job_web_notify
3453
#: model:ir.model.fields,field_description:queue_job_web_notify.field_queue_job_function__is_web_notify_failure_enabled
3554
msgid "Notify on failure"

queue_job_web_notify/models/queue_job.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ def _get_web_notify_failure_title(self):
1111
self.ensure_one()
1212
return _("Job failed")
1313

14+
def _get_web_notify_done_title(self):
15+
self.ensure_one()
16+
return _("Job done")
17+
1418
def _get_web_notify_failure_message(self):
1519
self.ensure_one()
1620
return self.display_name
1721

22+
def _get_web_notify_done_message(self):
23+
self.ensure_one()
24+
return self.display_name
25+
1826
def _message_post_on_failure(self):
1927
res = super()._message_post_on_failure()
2028
for job in self:
@@ -26,3 +34,19 @@ def _message_post_on_failure(self):
2634
message=notification_message, title=notification_title, sticky=True
2735
)
2836
return res
37+
38+
def _message_post_on_done(self):
39+
for job in self:
40+
if not job.job_function_id.is_web_notify_done_enabled:
41+
continue
42+
notification_title = job._get_web_notify_done_title()
43+
notification_message = job._get_web_notify_done_message()
44+
job.user_id.notify_success(
45+
message=notification_message, title=notification_title, sticky=True
46+
)
47+
48+
def write(self, vals):
49+
result = super().write(vals)
50+
if vals.get("state") == "done":
51+
self._message_post_on_done()
52+
return result

queue_job_web_notify/models/queue_job_function.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ class QueueJobFunction(models.Model):
1212
help="Display a notification in the user interface when the job fails.",
1313
default=False,
1414
)
15+
is_web_notify_done_enabled = fields.Boolean(
16+
string="Notify on done",
17+
help="Display a notification in the user interface when the job is done.",
18+
default=False,
19+
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
This module extends the mail notification feature of Queue Job. It adds the possibility
2-
to enable the web notification of failed jobs. When enabled, the user will be notified
2+
to enable the web notification of failed or done jobs. When enabled, the user will be notified
33
by a web notification. The web notification is a pop-up message that appears in the
44
user's browser.

queue_job_web_notify/views/queue_job_function.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<xpath expr="//field[@name='name']/.." position="after">
1010
<group name="group_web_notify">
1111
<field name="is_web_notify_failure_enabled" />
12+
<field name="is_web_notify_done_enabled" />
1213
</group>
1314
</xpath>
1415
</field>

0 commit comments

Comments
 (0)