diff --git a/stock_inventory_discrepancy/README.rst b/stock_inventory_discrepancy/README.rst
index 581b1d00c059..b4af02aeaac1 100644
--- a/stock_inventory_discrepancy/README.rst
+++ b/stock_inventory_discrepancy/README.rst
@@ -50,6 +50,8 @@ Configuration
#. Modify the "Maximum Discrepancy Rate Threshold" either in a Warehouse or
in a location. If set to 0.0 in both the threshold is disabled.
+If necessary, update the "Inventory Discrepancy Control" under "Inventory > Settings" to enable or disable inventory discrepancy (enabled by default).
+
Usage
=====
diff --git a/stock_inventory_discrepancy/__manifest__.py b/stock_inventory_discrepancy/__manifest__.py
index c3fa9c8c26bf..d408af99e55f 100644
--- a/stock_inventory_discrepancy/__manifest__.py
+++ b/stock_inventory_discrepancy/__manifest__.py
@@ -14,11 +14,14 @@
"data": [
"security/stock_inventory_discrepancy_security.xml",
"security/ir.model.access.csv",
+ "data/ir_config_parameter.xml",
"views/stock_quant_view.xml",
"views/stock_warehouse_view.xml",
"views/stock_location_view.xml",
+ "views/res_config_settings_view.xml",
"wizards/confirm_discrepancy_wiz.xml",
],
+ "demo": ["demo/demo_ir_config_parameter.xml"],
"license": "AGPL-3",
"post_load": "post_load_hook",
"installable": True,
diff --git a/stock_inventory_discrepancy/data/ir_config_parameter.xml b/stock_inventory_discrepancy/data/ir_config_parameter.xml
new file mode 100644
index 000000000000..851d8fbe0f4a
--- /dev/null
+++ b/stock_inventory_discrepancy/data/ir_config_parameter.xml
@@ -0,0 +1,10 @@
+
+
+
+
+ stock_inventory_discrepancy.inventory_discrepancy_enable
+ 1
+
+
diff --git a/stock_inventory_discrepancy/demo/demo_ir_config_parameter.xml b/stock_inventory_discrepancy/demo/demo_ir_config_parameter.xml
new file mode 100644
index 000000000000..d0b90856f542
--- /dev/null
+++ b/stock_inventory_discrepancy/demo/demo_ir_config_parameter.xml
@@ -0,0 +1,9 @@
+
+
+
+ stock_inventory_discrepancy.inventory_discrepancy_enable
+ 0
+
+
diff --git a/stock_inventory_discrepancy/models/__init__.py b/stock_inventory_discrepancy/models/__init__.py
index cc20d5da4779..df9525a42f95 100644
--- a/stock_inventory_discrepancy/models/__init__.py
+++ b/stock_inventory_discrepancy/models/__init__.py
@@ -3,3 +3,4 @@
from . import stock_quant
from . import stock_warehouse
from . import stock_location
+from . import res_config_settings
diff --git a/stock_inventory_discrepancy/models/res_config_settings.py b/stock_inventory_discrepancy/models/res_config_settings.py
new file mode 100644
index 000000000000..80c4b588c719
--- /dev/null
+++ b/stock_inventory_discrepancy/models/res_config_settings.py
@@ -0,0 +1,38 @@
+# Copyright 2024 Quartile Limited
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
+
+from odoo import api, fields, models
+
+
+class ResConfigSettings(models.TransientModel):
+ _inherit = "res.config.settings"
+
+ inventory_discrepancy_enable = fields.Boolean(
+ string="Inventory Discrepancy Control",
+ help="Block validation of the inventory adjustment if discrepancy exceeds "
+ "the threshold.",
+ )
+
+ @api.model
+ def get_values(self):
+ res = super(ResConfigSettings, self).get_values()
+ param = self.env["ir.config_parameter"].sudo()
+ inventory_discrepancy_enable = (
+ param.get_param(
+ "stock_inventory_discrepancy.inventory_discrepancy_enable", default="0"
+ )
+ == "1"
+ )
+ res.update(
+ inventory_discrepancy_enable=inventory_discrepancy_enable,
+ )
+ return res
+
+ # pylint: disable=missing-return
+ def set_values(self):
+ super(ResConfigSettings, self).set_values()
+ param = self.env["ir.config_parameter"].sudo()
+ param.set_param(
+ "stock_inventory_discrepancy.inventory_discrepancy_enable",
+ "1" if self.inventory_discrepancy_enable else "0",
+ )
diff --git a/stock_inventory_discrepancy/models/stock_quant.py b/stock_inventory_discrepancy/models/stock_quant.py
index 2674848b3e1d..c8c9006ec0bd 100644
--- a/stock_inventory_discrepancy/models/stock_quant.py
+++ b/stock_inventory_discrepancy/models/stock_quant.py
@@ -76,6 +76,13 @@ def _compute_has_over_discrepancy(self):
def action_apply_inventory(self):
if self.env.context.get("skip_exceeded_discrepancy", False):
return super().action_apply_inventory()
+ inventory_discrepancy_enable = (
+ self.env["ir.config_parameter"]
+ .sudo()
+ .get_param("stock_inventory_discrepancy.inventory_discrepancy_enable")
+ )
+ if inventory_discrepancy_enable == "0":
+ return super().action_apply_inventory()
over_discrepancy = self.filtered(lambda r: r.has_over_discrepancy)
if over_discrepancy:
action = self.env["ir.actions.act_window"]._for_xml_id(
diff --git a/stock_inventory_discrepancy/readme/CONFIGURE.rst b/stock_inventory_discrepancy/readme/CONFIGURE.rst
index 9d5628d89493..ecadb15a0f89 100644
--- a/stock_inventory_discrepancy/readme/CONFIGURE.rst
+++ b/stock_inventory_discrepancy/readme/CONFIGURE.rst
@@ -2,3 +2,5 @@
Warehouse Management" > Locations".
#. Modify the "Maximum Discrepancy Rate Threshold" either in a Warehouse or
in a location. If set to 0.0 in both the threshold is disabled.
+
+If necessary, update the "Inventory Discrepancy Control" under "Inventory > Settings" to enable or disable inventory discrepancy (enabled by default).
diff --git a/stock_inventory_discrepancy/static/description/index.html b/stock_inventory_discrepancy/static/description/index.html
index 1fa78ef401c4..13101d8d917d 100644
--- a/stock_inventory_discrepancy/static/description/index.html
+++ b/stock_inventory_discrepancy/static/description/index.html
@@ -399,6 +399,7 @@
Modify the “Maximum Discrepancy Rate Threshold” either in a Warehouse or
in a location. If set to 0.0 in both the threshold is disabled.
+If necessary, update the “Inventory Discrepancy Control” under “Inventory > Settings” to enable or disable inventory discrepancy (enabled by default).
diff --git a/stock_inventory_discrepancy/tests/test_inventory_discrepancy.py b/stock_inventory_discrepancy/tests/test_inventory_discrepancy.py
index 29098a49391e..77022e6188d7 100644
--- a/stock_inventory_discrepancy/tests/test_inventory_discrepancy.py
+++ b/stock_inventory_discrepancy/tests/test_inventory_discrepancy.py
@@ -10,6 +10,10 @@
class TestInventoryDiscrepancy(TransactionCase):
def setUp(self):
super().setUp()
+ # Enable the configuration using ir.config_parameter
+ self.env["ir.config_parameter"].sudo().set_param(
+ "stock_inventory_discrepancy.inventory_discrepancy_enable", "1"
+ )
self.obj_location = self.env["stock.location"]
self.obj_product = self.env["product.product"]
self.obj_warehouse = self.env["stock.warehouse"]
diff --git a/stock_inventory_discrepancy/views/res_config_settings_view.xml b/stock_inventory_discrepancy/views/res_config_settings_view.xml
new file mode 100644
index 000000000000..6c70feacf3bf
--- /dev/null
+++ b/stock_inventory_discrepancy/views/res_config_settings_view.xml
@@ -0,0 +1,26 @@
+
+
+
+ res.config.settings - inventory_discrepancy
+ res.config.settings
+
+
+
+
+
+
+
+
+
+
+ Block validation of the inventory adjustment if discrepancy exceeds the threshold.
+
+
+
+
+
+
+