Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions queue_job_alert_running/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
=======================
Job Queue Alert Running
=======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:09e6da1c23c22c23cef1bd7a94382d7d1229403def5111ede114c21ed49ac853
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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 a
computed ``is_job_running`` boolean field and automatically displays a
warning banner on form views when a record is currently the target of a
non-terminal queue job, helping prevent concurrent editing of the same
record.

The flag is derived from the actual ``queue.job`` state (pending,
enqueued, started, wait_dependencies), so there is nothing to call
before or after a job: enqueue work with ``with_delay()`` and the banner
reflects reality.

**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"]

def action_process(self):
self.with_delay()._process_in_background()

The mixin computes ``is_job_running`` from the real ``queue.job`` state,
so the banner appears while any job targets the record and disappears as
soon as the job reaches a terminal state (done / failed / cancelled)
even on error.

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 <https://github.com/OCA/queue/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 <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**>`_.

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

Credits
=======

Authors
-------

* Ecosoft

Contributors
------------

- Saran Lim. <saranl@ecosoft.co.th>

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 <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-Saran440|

This module is part of the `OCA/queue <https://github.com/OCA/queue/tree/18.0/queue_job_alert_running>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions queue_job_alert_running/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from . import models
17 changes: 17 additions & 0 deletions queue_job_alert_running/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2026 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"],
}
3 changes: 3 additions & 0 deletions queue_job_alert_running/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from . import queue_job_status_mixin
56 changes: 56 additions & 0 deletions queue_job_alert_running/models/queue_job_status_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2026 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.addons.queue_job.job import ENQUEUED, PENDING, STARTED, WAIT_DEPENDENCIES

#: queue.job states that are not terminal yet (done / cancelled / failed).
RUNNING_STATES = (WAIT_DEPENDENCIES, PENDING, ENQUEUED, STARTED)


class QueueJobStatusMixin(models.AbstractModel):
_name = "queue.job.status.mixin"
_description = "Queue Job Status Mixin"

is_job_running = fields.Boolean(compute="_compute_is_job_running")

def _compute_is_job_running(self):
"""True when at least one non-terminal queue.job targets this record."""
target_ids = set(self.ids)
if not target_ids:
self.is_job_running = False
return

jobs = (
self.env["queue.job"]
.sudo()
.search_fetch(
[
("model_name", "=", self._name),
("state", "in", RUNNING_STATES),
],
["records"],
)
)
running_ids = {
record_id
for job in jobs
for record_id in job.records.ids
if record_id in target_ids
}
for record in self:
record.is_job_running = record.id in running_ids

@api.model
def _get_view(self, view_id=None, view_type="form", **options):
arch, view = super()._get_view(view_id=view_id, view_type=view_type, **options)
if view_type == "form":
for sheet in arch.xpath("/form/sheet"):
label = self.env["ir.qweb"]._render(
"queue_job_alert_running.queue_running_label", {}
)
sheet.addprevious(etree.fromstring(label))
return arch, view
3 changes: 3 additions & 0 deletions queue_job_alert_running/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions queue_job_alert_running/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Saran Lim. \<<saranl@ecosoft.co.th>\>
8 changes: 8 additions & 0 deletions queue_job_alert_running/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This addon provides a mixin (`queue.job.status.mixin`) that adds a computed
`is_job_running` boolean field and automatically displays a warning banner on form views
when a record is currently the target of a non-terminal queue job, helping prevent
concurrent editing of the same record.

The flag is derived from the actual `queue.job` state (pending, enqueued, started,
wait_dependencies), so there is nothing to call before or after a job: enqueue work with
`with_delay()` and the banner reflects reality.
19 changes: 19 additions & 0 deletions queue_job_alert_running/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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"]

def action_process(self):
self.with_delay()._process_in_background()
```

The mixin computes `is_job_running` from the real `queue.job` state, so the banner
appears while any job targets the record and disappears as soon as the job reaches a
terminal state (done / failed / cancelled) even on error.

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."_
Loading
Loading