diff --git a/queue_job_web_notify/README.rst b/queue_job_web_notify/README.rst index bdd01e18db..7a902700b7 100644 --- a/queue_job_web_notify/README.rst +++ b/queue_job_web_notify/README.rst @@ -2,7 +2,7 @@ Queue Job Web Notify ==================== -.. +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! @@ -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. diff --git a/queue_job_web_notify/i18n/fr.po b/queue_job_web_notify/i18n/fr.po index e5821e73fa..263350eb0f 100644 --- a/queue_job_web_notify/i18n/fr.po +++ b/queue_job_web_notify/i18n/fr.po @@ -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" @@ -22,11 +22,24 @@ 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 @@ -34,6 +47,11 @@ msgstr "" 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" diff --git a/queue_job_web_notify/i18n/queue_job_web_notify.pot b/queue_job_web_notify/i18n/queue_job_web_notify.pot index 463d6b859e..782203de85 100644 --- a/queue_job_web_notify/i18n/queue_job_web_notify.pot +++ b/queue_job_web_notify/i18n/queue_job_web_notify.pot @@ -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" @@ -18,11 +20,23 @@ 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 @@ -30,6 +44,11 @@ msgstr "" 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" diff --git a/queue_job_web_notify/models/queue_job.py b/queue_job_web_notify/models/queue_job.py index 0f2d5e8a81..a21143fe5e 100644 --- a/queue_job_web_notify/models/queue_job.py +++ b/queue_job_web_notify/models/queue_job.py @@ -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): @@ -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") + 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 + def _message_post_on_failure(self): res = super()._message_post_on_failure() for job in self: @@ -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( + 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 diff --git a/queue_job_web_notify/models/queue_job_function.py b/queue_job_web_notify/models/queue_job_function.py index 5633d1e46c..1271cf9dc2 100644 --- a/queue_job_web_notify/models/queue_job_function.py +++ b/queue_job_web_notify/models/queue_job_function.py @@ -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, + ) diff --git a/queue_job_web_notify/readme/DESCRIPTION.md b/queue_job_web_notify/readme/DESCRIPTION.md index 8f1dbc70c0..941dacb915 100644 --- a/queue_job_web_notify/readme/DESCRIPTION.md +++ b/queue_job_web_notify/readme/DESCRIPTION.md @@ -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. diff --git a/queue_job_web_notify/views/queue_job_function.xml b/queue_job_web_notify/views/queue_job_function.xml index 7940f58603..ed26d14075 100644 --- a/queue_job_web_notify/views/queue_job_function.xml +++ b/queue_job_web_notify/views/queue_job_function.xml @@ -9,6 +9,7 @@ +