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
136 changes: 136 additions & 0 deletions product_state_shortage/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
.. 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
======================

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

.. |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
: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
: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 extends the ``product.state`` model to manage product states
during stock operations. It introduces the concept of a shortage state,
allowing products to automatically revert to their default state when
their available quantity becomes positive.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

**Business Need**

This module addresses the need to manage product states effectively in
scenarios where stock shortages occur. It ensures that products marked
as in shortage automatically revert to their default state when their
available quantity is updated to a positive value.

**Approach**

The module introduces a boolean field ``is_shortage`` in the
``product.state`` model. When enabled, a cron will watch for products
under this state and trigger a reset of the products state upon
detecting a positive available quantity.

Configuration
=============

To configure this module, you need to:

1. Navigate to the **Inventory** module.
2. Go to **Sales > Configuration > Products > Product States**.
3. Create or edit a product state and enable the **Is Shortage State**
checkbox.
4. Save the changes.

This configuration ensures that products in the specified state will be
watched by a cron to automatically revert to the default state when
their available quantity becomes positive.

Usage
=====

To use this module, you need to:

1. Navigate to the **Inventory** module.
2. Go to **Sales > Configuration > Products > Product States** and
create a state with the **Is Shortage State** checkbox enabled.
3. Assign the shortage state to products as needed.
4. A cron will watch those products so that when the available quantity
of such a product becomes positive, it will automatically revert to
the default state.

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%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.com
(https://www.acsone.eu/)

Other credits
-------------

The development of this module has been financially supported by:

- ACSONE SA/NV

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>`_ 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/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions product_state_shortage/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2026 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Product State Shortage",
"summary": """Enables to declare a product state as a "shortage" state.
Such a state will automatically resolve to default state whenever new stock
is received for this product avoiding the need for manual intervention""",
"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", "stock"],
"data": [
"views/product_state.xml",
],
"demo": [],
}
16 changes: 16 additions & 0 deletions product_state_shortage/data/ir_cron_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="ir_cron_reset_product_shortage_state" model="ir.cron">
<field
name="name"
>Product: Reset Shortage States based on Available Stock</field>
<field name="model_id" ref="product.model_product_template" />
<field name="state">code</field>
<field name="code">model.cron_reset_shortage_states()</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="active" eval="True" />
</record>
</odoo>
2 changes: 2 additions & 0 deletions product_state_shortage/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import product_state
from . import product_template
26 changes: 26 additions & 0 deletions product_state_shortage/models/product_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2026 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class ProductState(models.Model):
_inherit = "product.state"

is_shortage = fields.Boolean(
string="Is Shortage State",
help="If checked, products in this state will be processed by a "
"cron to revert to default state if stock is available.",
)

@api.constrains("is_shortage", "default")
def _check_shortage_not_default(self):
for record in self:
if record.is_shortage and record.default:
raise ValidationError(
_(
"A product state cannot be both the 'Default' state and "
"a 'Shortage' state at the same time."
)
)
30 changes: 30 additions & 0 deletions product_state_shortage/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2026 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


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

def _reset_default_state(self):
if default_state := self._get_default_product_state():
self.write({"product_state_id": default_state.id})

@api.model
def cron_reset_shortage_states(self):
"""
Finds products in a 'shortage' state that now have physical stock
and resets them to the default state.
"""
shortage_states = self.env["product.state"].search([("is_shortage", "=", True)])
if not shortage_states:
return

templates = self.search([("product_state_id", "in", shortage_states.ids)])

templates_to_reset = templates.filtered(
lambda t: any(p.qty_available > 0 for p in t.product_variant_ids)
)

templates_to_reset._reset_default_state()
8 changes: 8 additions & 0 deletions product_state_shortage/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
To configure this module, you need to:

1. Navigate to the **Inventory** module.
2. Go to **Sales > Configuration > Products > Product States**.
3. Create or edit a product state and enable the **Is Shortage State** checkbox.
4. Save the changes.

This configuration ensures that products in the specified state will be watched by a cron to automatically revert to the default state when their available quantity becomes positive.
7 changes: 7 additions & 0 deletions product_state_shortage/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**Business Need**

This module addresses the need to manage product states effectively in scenarios where stock shortages occur. It ensures that products marked as in shortage automatically revert to their default state when their available quantity is updated to a positive value.

**Approach**

The module introduces a boolean field `is_shortage` in the `product.state` model. When enabled, a cron will watch for products under this state and trigger a reset of the products state upon detecting a positive available quantity.
1 change: 1 addition & 0 deletions product_state_shortage/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Nicolas Delbovier <nicolas.delbovier@acsone.com> (https://www.acsone.eu/)
3 changes: 3 additions & 0 deletions product_state_shortage/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The development of this module has been financially supported by:

- ACSONE SA/NV
1 change: 1 addition & 0 deletions product_state_shortage/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module extends the `product.state` model to manage product states during stock operations. It introduces the concept of a shortage state, allowing products to automatically revert to their default state when their available quantity becomes positive.
6 changes: 6 additions & 0 deletions product_state_shortage/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
To use this module, you need to:

1. Navigate to the **Inventory** module.
2. Go to **Sales > Configuration > Products > Product States** and create a state with the **Is Shortage State** checkbox enabled.
3. Assign the shortage state to products as needed.
4. A cron will watch those products so that when the available quantity of such a product becomes positive, it will automatically revert to the default state.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading