From 553548285a7ed87a41632f55c6e04b4b87bdfe6a Mon Sep 17 00:00:00 2001 From: Saran440 Date: Thu, 4 Jun 2026 16:42:27 +0700 Subject: [PATCH] [18.0][ADD] queue_job_alert_running --- queue_job_alert_running/README.rst | 123 +++++ queue_job_alert_running/__init__.py | 3 + queue_job_alert_running/__manifest__.py | 17 + queue_job_alert_running/models/__init__.py | 3 + .../models/queue_job_status_mixin.py | 57 +++ queue_job_alert_running/pyproject.toml | 3 + .../readme/CONTRIBUTORS.md | 1 + queue_job_alert_running/readme/DESCRIPTION.md | 1 + queue_job_alert_running/readme/USAGE.md | 30 ++ .../static/description/icon.png | Bin 0 -> 1803 bytes .../static/description/icon.svg | 127 +++++ .../static/description/index.html | 463 ++++++++++++++++++ .../templates/queue_running_templates.xml | 17 + 13 files changed, 845 insertions(+) create mode 100644 queue_job_alert_running/README.rst create mode 100644 queue_job_alert_running/__init__.py create mode 100644 queue_job_alert_running/__manifest__.py create mode 100644 queue_job_alert_running/models/__init__.py create mode 100644 queue_job_alert_running/models/queue_job_status_mixin.py create mode 100644 queue_job_alert_running/pyproject.toml create mode 100644 queue_job_alert_running/readme/CONTRIBUTORS.md create mode 100644 queue_job_alert_running/readme/DESCRIPTION.md create mode 100644 queue_job_alert_running/readme/USAGE.md create mode 100644 queue_job_alert_running/static/description/icon.png create mode 100644 queue_job_alert_running/static/description/icon.svg create mode 100644 queue_job_alert_running/static/description/index.html create mode 100644 queue_job_alert_running/templates/queue_running_templates.xml diff --git a/queue_job_alert_running/README.rst b/queue_job_alert_running/README.rst new file mode 100644 index 0000000000..3ab12b70cf --- /dev/null +++ b/queue_job_alert_running/README.rst @@ -0,0 +1,123 @@ +======================= +Job Queue Alert Running +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b6e605728ea05be0bf98dbe6e94c197bab21882e965286ef214f719e252b444e + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github + :target: https://github.com/OCA/queue/tree/18.0/queue_job_alert_running + :alt: OCA/queue +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/queue-18-0/queue-18-0-queue_job_alert_running + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/queue&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This addon provides a mixin (``queue.job.status.mixin``) that adds an +``is_job_running`` boolean field and automatically displays a warning +banner on form views when a record has a running queue job, helping +prevent concurrent editing of the same record. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module: + +1. Inherit ``queue.job.status.mixin`` in your model: + +.. code:: python + + class MyModel(models.Model): + _name = "my.model" + _inherit = ["queue.job.status.mixin"] + +2. Call ``action_mark_running()`` when a queue job starts (e.g., before + ``with_delay()``): + +.. code:: python + + def action_process(self): + self.action_mark_running() + self.with_delay()._process_in_background() + +3. Call ``action_mark_done()`` inside the background job when finished: + +.. code:: python + + def _process_in_background(self): + try: + # ... do work ... + pass + finally: + self.action_mark_done() + +When ``is_job_running`` is ``True``, a yellow warning banner appears at +the top of the form view: *"This Record is running in queue job."* + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Ecosoft + +Contributors +------------ + +- Saran Lim. + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-Saran440| image:: https://github.com/Saran440.png?size=40px + :target: https://github.com/Saran440 + :alt: Saran440 + +Current `maintainer `__: + +|maintainer-Saran440| + +This module is part of the `OCA/queue `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/queue_job_alert_running/__init__.py b/queue_job_alert_running/__init__.py new file mode 100644 index 0000000000..5268169bf6 --- /dev/null +++ b/queue_job_alert_running/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from . import models diff --git a/queue_job_alert_running/__manifest__.py b/queue_job_alert_running/__manifest__.py new file mode 100644 index 0000000000..c8768d7477 --- /dev/null +++ b/queue_job_alert_running/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2025 Ecosoft Co., Ltd. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +{ + "name": "Job Queue Alert Running", + "version": "18.0.1.0.0", + "author": "Ecosoft, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/queue", + "summary": "Show a warning banner when a record has a running queue job", + "license": "AGPL-3", + "category": "Generic Modules", + "depends": ["queue_job"], + "data": [ + "templates/queue_running_templates.xml", + ], + "maintainers": ["Saran440"], +} diff --git a/queue_job_alert_running/models/__init__.py b/queue_job_alert_running/models/__init__.py new file mode 100644 index 0000000000..58e6847e91 --- /dev/null +++ b/queue_job_alert_running/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from . import queue_job_status_mixin diff --git a/queue_job_alert_running/models/queue_job_status_mixin.py b/queue_job_alert_running/models/queue_job_status_mixin.py new file mode 100644 index 0000000000..e891e1c4b2 --- /dev/null +++ b/queue_job_alert_running/models/queue_job_status_mixin.py @@ -0,0 +1,57 @@ +# Copyright 2025 Ecosoft Co., Ltd. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from lxml import etree + +from odoo import api, fields, models +from odoo.tools.misc import frozendict + + +class QueueJobStatusMixin(models.AbstractModel): + _name = "queue.job.status.mixin" + _description = "Queue Job Status Mixin" + + is_job_running = fields.Boolean(copy=False) + + def action_mark_running(self): + self.write({"is_job_running": True}) + + def action_mark_done(self): + self.write({"is_job_running": False}) + + @api.model + def _merge_view_fields(self, all_models: dict, new_models: dict): + """Merge new_models into all_models. + Both are {modelname(str) > fields(tuple)}.""" + for model, view_fields in new_models.items(): + if model in all_models: + all_models[model] = tuple(set(all_models[model]) | set(view_fields)) + else: + all_models[model] = tuple(view_fields) + + def _add_queue_running_label(self, node, params): + str_element = self.env["ir.qweb"]._render( + "queue_job_alert_running.queue_running_label", params + ) + new_node = etree.fromstring(str_element) + return new_node + + @api.model + def get_view(self, view_id=None, view_type="form", **options): + res = super().get_view(view_id=view_id, view_type=view_type, **options) + View = self.env["ir.ui.view"] + if view_type == "form": + doc = etree.XML(res["arch"]) + params = {} + all_models = res["models"].copy() # {modelname(str) > fields(tuple)} + for node in doc.xpath("/form/sheet"): + # _add_queue_running_label process + new_node = self._add_queue_running_label(node, params) + new_arch, new_models = View.postprocess_and_fields(new_node, self._name) + new_node = etree.fromstring(new_arch) + for new_element in new_node: + node.addprevious(new_element) + self._merge_view_fields(all_models, new_models) + res["arch"] = etree.tostring(doc) + res["models"] = frozendict(all_models) + return res diff --git a/queue_job_alert_running/pyproject.toml b/queue_job_alert_running/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/queue_job_alert_running/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/queue_job_alert_running/readme/CONTRIBUTORS.md b/queue_job_alert_running/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..8d0d33151c --- /dev/null +++ b/queue_job_alert_running/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Saran Lim. \<\> diff --git a/queue_job_alert_running/readme/DESCRIPTION.md b/queue_job_alert_running/readme/DESCRIPTION.md new file mode 100644 index 0000000000..5bfc2a5a7e --- /dev/null +++ b/queue_job_alert_running/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This addon provides a mixin (`queue.job.status.mixin`) that adds an `is_job_running` boolean field and automatically displays a warning banner on form views when a record has a running queue job, helping prevent concurrent editing of the same record. diff --git a/queue_job_alert_running/readme/USAGE.md b/queue_job_alert_running/readme/USAGE.md new file mode 100644 index 0000000000..526c67c0f7 --- /dev/null +++ b/queue_job_alert_running/readme/USAGE.md @@ -0,0 +1,30 @@ +To use this module: + +1. Inherit `queue.job.status.mixin` in your model: + +```python +class MyModel(models.Model): + _name = "my.model" + _inherit = ["queue.job.status.mixin"] +``` + +2. Call `action_mark_running()` when a queue job starts (e.g., before `with_delay()`): + +```python +def action_process(self): + self.action_mark_running() + self.with_delay()._process_in_background() +``` + +3. Call `action_mark_done()` inside the background job when finished: + +```python +def _process_in_background(self): + try: + # ... do work ... + pass + finally: + self.action_mark_done() +``` + +When `is_job_running` is `True`, a yellow warning banner appears at the top of the form view: *"This Record is running in queue job."* diff --git a/queue_job_alert_running/static/description/icon.png b/queue_job_alert_running/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a735e94d10274d83c86106188a9339a8132d3e0c GIT binary patch literal 1803 zcmah~c~H~W7XAgv(y&8>7!g9?2_uX6j9M0H2w{85B1;<{1rjv~0!hFHRF)XSs%&K| zy8?01ZzMf}g@Olm>$+c8(L7t8l94@SXuM#Y%*o&QRbl=pI4m0ANqL(m=VhOB6+L z*Lhdsd4F2?`FL_11&EK2w~3@iojXOQQ*3B)XUZj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FwRfP9Cw*?0`4OzpVh;{rTgy$KKSB + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + diff --git a/queue_job_alert_running/static/description/index.html b/queue_job_alert_running/static/description/index.html new file mode 100644 index 0000000000..26b624c805 --- /dev/null +++ b/queue_job_alert_running/static/description/index.html @@ -0,0 +1,463 @@ + + + + + +Job Queue Alert Running + + + +
+

Job Queue Alert Running

+ + +

Beta License: AGPL-3 OCA/queue Translate me on Weblate Try me on Runboat

+

This addon provides a mixin (queue.job.status.mixin) that adds an +is_job_running boolean field and automatically displays a warning +banner on form views when a record has a running queue job, helping +prevent concurrent editing of the same record.

+

Table of contents

+ +
+

Usage

+

To use this module:

+
    +
  1. Inherit queue.job.status.mixin in your model:
  2. +
+
+class MyModel(models.Model):
+    _name = "my.model"
+    _inherit = ["queue.job.status.mixin"]
+
+
    +
  1. Call action_mark_running() when a queue job starts (e.g., before +with_delay()):
  2. +
+
+def action_process(self):
+    self.action_mark_running()
+    self.with_delay()._process_in_background()
+
+
    +
  1. Call action_mark_done() inside the background job when finished:
  2. +
+
+def _process_in_background(self):
+    try:
+        # ... do work ...
+        pass
+    finally:
+        self.action_mark_done()
+
+

When is_job_running is True, a yellow warning banner appears at +the top of the form view: “This Record is running in queue job.”

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Ecosoft
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

Saran440

+

This module is part of the OCA/queue project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/queue_job_alert_running/templates/queue_running_templates.xml b/queue_job_alert_running/templates/queue_running_templates.xml new file mode 100644 index 0000000000..cb0683e679 --- /dev/null +++ b/queue_job_alert_running/templates/queue_running_templates.xml @@ -0,0 +1,17 @@ + + + +