diff --git a/product_stock_state/__manifest__.py b/product_stock_state/__manifest__.py
index e70622f7ad9..d928bea3f92 100644
--- a/product_stock_state/__manifest__.py
+++ b/product_stock_state/__manifest__.py
@@ -7,8 +7,11 @@
{
"name": "Product Stock State",
- "summary": "Compute the state of a product's stock"
- "the stock level and sale_ok field",
+ "summary": """Compute the state of a product's stock
+ Offers 'sale ok' field
+ Tracks the stock level and manage the following product's stock states based on rules :
+ 'on demand' 'in_stock' 'limited stock' 'resupplying' 'out of stock'
+ """,
"version": "14.0.1.0.1",
"website": "https://github.com/OCA/product-attribute",
"author": " Akretion, GRAP, Odoo Community Association (OCA)",
diff --git a/product_stock_state/i18n/fr.po b/product_stock_state/i18n/fr.po
index 59f2e3a9416..ea77c376900 100644
--- a/product_stock_state/i18n/fr.po
+++ b/product_stock_state/i18n/fr.po
@@ -90,6 +90,17 @@ msgstr ""
msgid "Manual Stock State Threshold"
msgstr "Seuil pour l'état du stock manuel"
+#. module: product_stock_state
+#: model:ir.model.fields,field_description:product_stock_state.field_product_product__on_demand
+#: model:ir.model.fields,field_description:product_stock_state.field_product_template__on_demand
+msgid "On Demand"
+msgstr "Sur demande"
+
+#. module: product_stock_state
+#: model:ir.model.fields,help:product_stock_state.field_product_template_on_demand
+msgid "This field allows you to force the stock state to the on-demand value"
+msgstr "Ce champ vous permet de forcer l'état du stock à 'À la demande'"
+
#. module: product_stock_state
#: model:ir.model,name:product_stock_state.model_product_product
msgid "Product"
@@ -174,6 +185,12 @@ msgstr ""
"elle n'est pas définie, Odoo utilisera le seuil défini au niveau de "
"l'entreprise."
+#. module: product_stock_state
+#: model:ir.model.fields,help:product_stock_state.field_product_product__on_demand
+#: model:ir.model.fields,help:product_stock_state.field_product_template__on_demand
+msgid "This field allows you to force the stock state to the on-demand value"
+msgstr "Ce champs vous permet de forcer l'état du stock à 'A la demande'"
+
#. module: product_stock_state
#: model:product.product,uom_name:product_stock_state.product_setting_by_company
#: model:product.product,uom_name:product_stock_state.product_setting_by_product
diff --git a/product_stock_state/i18n/product_stock_state.pot b/product_stock_state/i18n/product_stock_state.pot
index f46218e7062..cc952e744f5 100644
--- a/product_stock_state/i18n/product_stock_state.pot
+++ b/product_stock_state/i18n/product_stock_state.pot
@@ -79,6 +79,17 @@ msgstr ""
msgid "Manual Stock State Threshold"
msgstr ""
+#. module: product_stock_state
+#: model:ir.model.fields,field_description:product_stock_state.field_product_product__on_demand
+#: model:ir.model.fields,field_description:product_stock_state.field_product_template__on_demand
+msgid "On Demand"
+msgstr ""
+
+#. module: product_stock_state
+#: model:ir.model.fields,help:product_stock_state.field_product_template__on_demand
+msgid "This field allows you to force the stock state to the on-demand value"
+msgstr ""
+
#. module: product_stock_state
#: model:ir.model,name:product_stock_state.model_product_product
msgid "Product"
diff --git a/product_stock_state/models/product_product.py b/product_stock_state/models/product_product.py
index 39960a0428e..16995ad32b2 100644
--- a/product_stock_state/models/product_product.py
+++ b/product_stock_state/models/product_product.py
@@ -16,6 +16,7 @@ class ProductProduct(models.Model):
_inherit = "product.product"
_STOCK_STATE_SELECTION = [
+ ("on_demand", "On Demand"),
("in_stock", "In Stock"),
("in_limited_stock", "In Limited Stock"),
("resupplying", "Resupplying"),
@@ -57,6 +58,9 @@ def _stock_state_check_resupplying(self, qty, precision):
def _stock_state_check_out_of_stock(self, qty, precision):
return True
+ def _stock_state_check_on_demand(self, qty, precision):
+ return self.on_demand
+
def _available_states(self):
return [x[0] for x in self._selection_stock_state()]
@@ -65,8 +69,14 @@ def _available_states(self):
"incoming_qty",
"stock_state_threshold",
"company_id.stock_state_threshold",
+ "on_demand",
)
def _compute_stock_state(self):
+ """
+ This method updates {stock_state} of each triggered {product}.
+ {stock_state} = first {state} where {product}_stock_state_check_{state} is True
+ {state} ordering is insured by _available_states method
+ """
precision = self.env["decimal.precision"].precision_get("Stock Threshold")
for product in self:
qty_available = product._get_qty_available_for_stock_state()
diff --git a/product_stock_state/models/product_template.py b/product_stock_state/models/product_template.py
index 2ba49b7c45f..e33cbbefd8a 100644
--- a/product_stock_state/models/product_template.py
+++ b/product_stock_state/models/product_template.py
@@ -25,6 +25,11 @@ class ProductTemplate(models.Model):
manual_stock_state_threshold = fields.Float(digits="Stock Threshold")
+ on_demand = fields.Boolean(
+ default=False,
+ help="This field allows you to force the stock state to the on-demand value"
+ )
+
@api.depends("categ_id.stock_state_threshold", "manual_stock_state_threshold")
def _compute_stock_state_threshold(self):
for rec in self:
diff --git a/product_stock_state/tests/test_product_stock_state.py b/product_stock_state/tests/test_product_stock_state.py
index 4fed84ba0a8..0ab889a3f35 100644
--- a/product_stock_state/tests/test_product_stock_state.py
+++ b/product_stock_state/tests/test_product_stock_state.py
@@ -53,3 +53,17 @@ def test_04_category_setting_inherit(self):
def test_05_state_out_of_stock(self):
"""Test Stock State computation"""
self.assertEqual(self.product_threshold_on_product.stock_state, "out_of_stock")
+
+ def test_06_state_on_demand_computation(self):
+ """Test on_demand = True Stock State computation
+ stock_state is set to 'on_demand' :
+ - regardless of the previous state
+ - regardless of the relative value of stock_state_threshold vs qty_available"""
+
+ stock_state_threshold = 30
+ self.product_threshold_on_product.stock_state_threshold = stock_state_threshold
+ self.product_threshold_on_product.on_demand = True
+
+ for qty in [stock_state_threshold + 1, stock_state_threshold - 1]:
+ self.product_threshold_on_product.qty_available = qty
+ self.assertEqual(self.product_threshold_on_product.stock_state, 'on_demand')
diff --git a/product_stock_state/views/product_template_view.xml b/product_stock_state/views/product_template_view.xml
index 913dd7e6036..e4ecacc9c87 100644
--- a/product_stock_state/views/product_template_view.xml
+++ b/product_stock_state/views/product_template_view.xml
@@ -5,9 +5,13 @@
-
-
-
+
+
+
+