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
99 changes: 99 additions & 0 deletions product_state_shortage_queue_job/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

================================
Product State Shortage Queue Job
================================

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

.. |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/license-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%2Fproduct--attribute-lightgray.png?logo=github
:target: https://github.com/OCA/product-attribute/tree/16.0/product_state_shortage_queue_job
:alt: OCA/product-attribute
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-attribute-16-0/product-attribute-16-0-product_state_shortage_queue_job
: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/product-attribute&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module enhances the integration between product state management
and the asynchronous queue job system.

When product states are automatically reset via the scheduled action
(cron) running as a queue job, this module ensures that detailed
feedback is captured directly on the job record.

**Table of contents**

.. contents::
:local:

Usage
=====

Usage
-----

1. Configure the cron
``Product: Reset Shortage States based on Available Stock`` to run as
a **Queue Job**.
2. When the job executes, navigate to the jobs list.
3. Open the finished job to see the chatter history, which will contain
the summary of all products processed and updated during that
execution.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/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/product-attribute/issues/new?body=module:%20product_state_shortage_queue_job%0Aversion:%2016.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
-------

* ACSONE SA/NV

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

- Nicolas Delbovier nicolas.delbovier@acsone.eu (https://www.acsone.eu/)

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.

This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/16.0/product_state_shortage_queue_job>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions product_state_shortage_queue_job/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions product_state_shortage_queue_job/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2026 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Product State Shortage Queue Job",
"summary": """Adds a summary log on the queue job record that
performed the shortage state reset""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-attribute",
"depends": ["product_state_shortage", "queue_job_cron"],
"data": [],
"demo": [],
}
1 change: 1 addition & 0 deletions product_state_shortage_queue_job/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_template
59 changes: 59 additions & 0 deletions product_state_shortage_queue_job/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2026 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from itertools import groupby

from odoo import _, models


class ProductTemplate(models.Model):
_inherit = "product.template"

def _before_reset_default_state_hook(self):
res = super()._before_reset_default_state_hook()

cron = self.env.ref(
"product_state_shortage.ir_cron_reset_product_shortage_state"
)
if not cron or not cron.run_as_queue_job:
return res

# This search seems a bit sub-optimal since the Job record is already
# somewhere inside the stack but the context here does not contain the
# Job's uuid because it got overridden
current_job = (
self.env["queue.job"]
.sudo()
.search(
[
("model_name", "=", "ir.cron"),
("state", "=", "started"),
("name", "=", cron.name),
],
limit=1,
order="date_started desc",
)
)
if not current_job:
return res

templates_by_state = {}
for state, tmpl_group in groupby(self, key=lambda t: t.product_state_id):
templates_by_state[state] = list(tmpl_group)

for state, templates in templates_by_state.items():
product_list_html = "".join(
[f"<li>{t._get_html_link()} (ID: {t.id})</li>" for t in templates]
)

message = _(
"<p>The following products were in state <strong>%(current_state)s</strong> "
"and have been reset to default state <strong>%(default_state)s</strong>:</p>"
"<ul>%(product_list)s</ul>",
current_state=state.display_name or _("N/A"),
default_state=self._get_default_product_state().display_name,
product_list=product_list_html,
)
current_job.message_post(body=message)

return res
1 change: 1 addition & 0 deletions product_state_shortage_queue_job/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Nicolas Delbovier <nicolas.delbovier@acsone.eu> (https://www.acsone.eu/)
6 changes: 6 additions & 0 deletions product_state_shortage_queue_job/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This module enhances the integration between product state management and the
asynchronous queue job system.

When product states are automatically reset via the scheduled action (cron)
running as a queue job, this module ensures that detailed feedback is
captured directly on the job record.
6 changes: 6 additions & 0 deletions product_state_shortage_queue_job/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Usage

1. Configure the cron `Product: Reset Shortage States based on Available Stock` to run as a **Queue Job**.
2. When the job executes, navigate to the jobs list.
3. Open the finished job to see the chatter history, which will contain
the summary of all products processed and updated during that execution.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading