diff --git a/queue_job_alert_running/README.rst b/queue_job_alert_running/README.rst new file mode 100644 index 000000000..3ab12b70c --- /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 000000000..5268169bf --- /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 000000000..c8768d747 --- /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 000000000..58e6847e9 --- /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 000000000..e891e1c4b --- /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 000000000..4231d0ccc --- /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 000000000..8d0d33151 --- /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 000000000..5bfc2a5a7 --- /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 000000000..526c67c0f --- /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 000000000..a735e94d1 Binary files /dev/null and b/queue_job_alert_running/static/description/icon.png differ diff --git a/queue_job_alert_running/static/description/icon.svg b/queue_job_alert_running/static/description/icon.svg new file mode 100644 index 000000000..653fcebfa --- /dev/null +++ b/queue_job_alert_running/static/description/icon.svg @@ -0,0 +1,127 @@ + + + + + + + + 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 000000000..26b624c80 --- /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 000000000..cb0683e67 --- /dev/null +++ b/queue_job_alert_running/templates/queue_running_templates.xml @@ -0,0 +1,17 @@ + + + +