From 78f5adebdc011b8321501e0e388ce22bef3c204d Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Wed, 20 Mar 2024 02:35:32 +0000 Subject: [PATCH] [IMP] stock_inventory_discrepancy: add system parameter configuration for enabling discrepancy check --- stock_inventory_discrepancy/README.rst | 3 +- stock_inventory_discrepancy/__manifest__.py | 3 ++ .../data/ir_config_parameter.xml | 10 +++++ .../demo/demo_ir_config_parameter.xml | 9 +++++ .../models/__init__.py | 1 + .../models/res_config_settings.py | 38 +++++++++++++++++++ .../models/stock_quant.py | 7 ++++ .../readme/CONFIGURE.rst | 1 + .../static/description/index.html | 3 +- .../tests/test_inventory_discrepancy.py | 4 ++ .../views/res_config_settings_view.xml | 26 +++++++++++++ 11 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 stock_inventory_discrepancy/data/ir_config_parameter.xml create mode 100644 stock_inventory_discrepancy/demo/demo_ir_config_parameter.xml create mode 100644 stock_inventory_discrepancy/models/res_config_settings.py create mode 100644 stock_inventory_discrepancy/views/res_config_settings_view.xml diff --git a/stock_inventory_discrepancy/README.rst b/stock_inventory_discrepancy/README.rst index 8c7804da9ca2..ede4611b3104 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:4f3341a6023c1b9f697578bd1e84d01cc9e8013e283b5119fc81bfe1a22d28ea !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |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 "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..7d1717a14b26 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 "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..db67d4d31f91 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:4f3341a6023c1b9f697578bd1e84d01cc9e8013e283b5119fc81bfe1a22d28ea !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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 “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 + + + +
    +
    + +
    +
    +
    +
    +
    +
    +
    +