Skip to content

Commit 9bd399f

Browse files
committed
[18.0][ADD] queue_job_alert_running
1 parent 1768b9f commit 9bd399f

15 files changed

Lines changed: 831 additions & 0 deletions

queue_job_alert_running/README.rst

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
=======================
2+
Job Queue Alert Running
3+
=======================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:09e6da1c23c22c23cef1bd7a94382d7d1229403def5111ede114c21ed49ac853
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github
20+
:target: https://github.com/OCA/queue/tree/18.0/queue_job_alert_running
21+
:alt: OCA/queue
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/queue-18-0/queue-18-0-queue_job_alert_running
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/queue&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This addon provides a mixin (``queue.job.status.mixin``) that adds a
32+
computed ``is_job_running`` boolean field and automatically displays a
33+
warning banner on form views when a record is currently the target of a
34+
non-terminal queue job, helping prevent concurrent editing of the same
35+
record.
36+
37+
The flag is derived from the actual ``queue.job`` state (pending,
38+
enqueued, started, wait_dependencies), so there is nothing to call
39+
before or after a job: enqueue work with ``with_delay()`` and the banner
40+
reflects reality.
41+
42+
**Table of contents**
43+
44+
.. contents::
45+
:local:
46+
47+
Usage
48+
=====
49+
50+
To use this module:
51+
52+
1. Inherit ``queue.job.status.mixin`` in your model:
53+
54+
.. code:: python
55+
56+
class MyModel(models.Model):
57+
_name = "my.model"
58+
_inherit = ["queue.job.status.mixin"]
59+
60+
def action_process(self):
61+
self.with_delay()._process_in_background()
62+
63+
The mixin computes ``is_job_running`` from the real ``queue.job`` state,
64+
so the banner appears while any job targets the record and disappears as
65+
soon as the job reaches a terminal state (done / failed / cancelled)
66+
even on error.
67+
68+
When ``is_job_running`` is ``True``, a yellow warning banner appears at
69+
the top of the form view: *"This Record is running in queue job."*
70+
71+
Bug Tracker
72+
===========
73+
74+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/queue/issues>`_.
75+
In case of trouble, please check there if your issue has already been reported.
76+
If you spotted it first, help us to smash it by providing a detailed and welcomed
77+
`feedback <https://github.com/OCA/queue/issues/new?body=module:%20queue_job_alert_running%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
78+
79+
Do not contact contributors directly about support or help with technical issues.
80+
81+
Credits
82+
=======
83+
84+
Authors
85+
-------
86+
87+
* Ecosoft
88+
89+
Contributors
90+
------------
91+
92+
- Saran Lim. <saranl@ecosoft.co.th>
93+
94+
Maintainers
95+
-----------
96+
97+
This module is maintained by the OCA.
98+
99+
.. image:: https://odoo-community.org/logo.png
100+
:alt: Odoo Community Association
101+
:target: https://odoo-community.org
102+
103+
OCA, or the Odoo Community Association, is a nonprofit organization whose
104+
mission is to support the collaborative development of Odoo features and
105+
promote its widespread use.
106+
107+
.. |maintainer-Saran440| image:: https://github.com/Saran440.png?size=40px
108+
:target: https://github.com/Saran440
109+
:alt: Saran440
110+
111+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
112+
113+
|maintainer-Saran440|
114+
115+
This module is part of the `OCA/queue <https://github.com/OCA/queue/tree/18.0/queue_job_alert_running>`_ project on GitHub.
116+
117+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
2+
3+
from . import models
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2026 Ecosoft Co., Ltd.
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3+
4+
{
5+
"name": "Job Queue Alert Running",
6+
"version": "18.0.1.0.0",
7+
"author": "Ecosoft, Odoo Community Association (OCA)",
8+
"website": "https://github.com/OCA/queue",
9+
"summary": "Show a warning banner when a record has a running queue job",
10+
"license": "AGPL-3",
11+
"category": "Generic Modules",
12+
"depends": ["queue_job"],
13+
"data": [
14+
"templates/queue_running_templates.xml",
15+
],
16+
"maintainers": ["Saran440"],
17+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
2+
3+
from . import queue_job_status_mixin
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2026 Ecosoft Co., Ltd.
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3+
4+
from lxml import etree
5+
6+
from odoo import api, fields, models
7+
8+
from odoo.addons.queue_job.job import ENQUEUED, PENDING, STARTED, WAIT_DEPENDENCIES
9+
10+
#: queue.job states that are not terminal yet (done / cancelled / failed).
11+
RUNNING_STATES = (WAIT_DEPENDENCIES, PENDING, ENQUEUED, STARTED)
12+
13+
14+
class QueueJobStatusMixin(models.AbstractModel):
15+
_name = "queue.job.status.mixin"
16+
_description = "Queue Job Status Mixin"
17+
18+
is_job_running = fields.Boolean(compute="_compute_is_job_running")
19+
20+
def _compute_is_job_running(self):
21+
"""True when at least one non-terminal queue.job targets this record."""
22+
target_ids = set(self.ids)
23+
if not target_ids:
24+
self.is_job_running = False
25+
return
26+
27+
jobs = (
28+
self.env["queue.job"]
29+
.sudo()
30+
.search_fetch(
31+
[
32+
("model_name", "=", self._name),
33+
("state", "in", RUNNING_STATES),
34+
],
35+
["records"],
36+
)
37+
)
38+
running_ids = {
39+
record_id
40+
for job in jobs
41+
for record_id in job.records.ids
42+
if record_id in target_ids
43+
}
44+
for record in self:
45+
record.is_job_running = record.id in running_ids
46+
47+
@api.model
48+
def _get_view(self, view_id=None, view_type="form", **options):
49+
arch, view = super()._get_view(view_id=view_id, view_type=view_type, **options)
50+
if view_type == "form":
51+
for sheet in arch.xpath("/form/sheet"):
52+
label = self.env["ir.qweb"]._render(
53+
"queue_job_alert_running.queue_running_label", {}
54+
)
55+
sheet.addprevious(etree.fromstring(label))
56+
return arch, view
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Saran Lim. \<<saranl@ecosoft.co.th>\>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This addon provides a mixin (`queue.job.status.mixin`) that adds a computed
2+
`is_job_running` boolean field and automatically displays a warning banner on form views
3+
when a record is currently the target of a non-terminal queue job, helping prevent
4+
concurrent editing of the same record.
5+
6+
The flag is derived from the actual `queue.job` state (pending, enqueued, started,
7+
wait_dependencies), so there is nothing to call before or after a job: enqueue work with
8+
`with_delay()` and the banner reflects reality.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
To use this module:
2+
3+
1. Inherit `queue.job.status.mixin` in your model:
4+
5+
```python
6+
class MyModel(models.Model):
7+
_name = "my.model"
8+
_inherit = ["queue.job.status.mixin"]
9+
10+
def action_process(self):
11+
self.with_delay()._process_in_background()
12+
```
13+
14+
The mixin computes `is_job_running` from the real `queue.job` state, so the banner
15+
appears while any job targets the record and disappears as soon as the job reaches a
16+
terminal state (done / failed / cancelled) even on error.
17+
18+
When `is_job_running` is `True`, a yellow warning banner appears at the top of the form
19+
view: _"This Record is running in queue job."_

0 commit comments

Comments
 (0)