diff --git a/stock_inventory_discrepancy/README.rst b/stock_inventory_discrepancy/README.rst index 8c7804da9ca2..327fae00721a 100644 --- a/stock_inventory_discrepancy/README.rst +++ b/stock_inventory_discrepancy/README.rst @@ -7,7 +7,7 @@ Stock Inventory Discrepancy !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:49949b52008fb335a36237b047619ef422c8377d3f70a291232c58658eb31ebd + !! source digest: sha256:386201b942050d56c8197f4a7fe6c841c875eff50214dc66bf3e94f7abdb96f2 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -49,6 +49,7 @@ Configuration 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. +#. Modify the "Enable 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 bbdeca59bbf5..fd4245ac29d1 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..d7f7e1da01b3 --- /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="Enable to show line discrepancies in inventory and block validation " + "if the 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 7ec8ef851049..1da34fa6047e 100644 --- a/stock_inventory_discrepancy/models/stock_quant.py +++ b/stock_inventory_discrepancy/models/stock_quant.py @@ -55,6 +55,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..3335b99f17b7 100644 --- a/stock_inventory_discrepancy/readme/CONFIGURE.rst +++ b/stock_inventory_discrepancy/readme/CONFIGURE.rst @@ -2,3 +2,4 @@ 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. +#. Modify the "Enable 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 57c3aa79beac..28d01e329194 100644 --- a/stock_inventory_discrepancy/static/description/index.html +++ b/stock_inventory_discrepancy/static/description/index.html @@ -367,7 +367,7 @@

Stock Inventory Discrepancy

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:49949b52008fb335a36237b047619ef422c8377d3f70a291232c58658eb31ebd +!! source digest: sha256:386201b942050d56c8197f4a7fe6c841c875eff50214dc66bf3e94f7abdb96f2 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runboat

Adds the capability to show the discrepancy of every line in an inventory and @@ -398,6 +398,7 @@

Configuration

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.
  • +
  • Modify the “Enable 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..5bc1b5e26e3e --- /dev/null +++ b/stock_inventory_discrepancy/views/res_config_settings_view.xml @@ -0,0 +1,26 @@ + + + + res.config.settings - inventory_discrepancy + res.config.settings + + + +
    +
    + +
    +
    +
    +
    +
    +
    +
    +