Skip to content

Commit

Permalink
[IMP] stock_inventory_discrepancy: add system parameter configuration…
Browse files Browse the repository at this point in the history
… for enabling discrepancy check
  • Loading branch information
AungKoKoLin1997 committed Jun 13, 2024
1 parent 8c475dc commit 726edca
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 2 deletions.
4 changes: 3 additions & 1 deletion stock_inventory_discrepancy/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:34ada4304b49d5c50ece64ebe7599d857948157aaa407477691260ed11341cd1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -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
=====

Expand Down
3 changes: 3 additions & 0 deletions stock_inventory_discrepancy/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions stock_inventory_discrepancy/data/ir_config_parameter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<!-- System Parameter for Enabling Inventory Discrepancy -->
<record id="param_inventory_discrepancy_enable" model="ir.config_parameter">
<field
name="key"
>stock_inventory_discrepancy.inventory_discrepancy_enable</field>
<field name="value">1</field> <!-- Enable by default -->
</record>
</odoo>
9 changes: 9 additions & 0 deletions stock_inventory_discrepancy/demo/demo_ir_config_parameter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="param_inventory_discrepancy_enable" model="ir.config_parameter">
<field
name="key"
>stock_inventory_discrepancy.inventory_discrepancy_enable</field>
<field name="value">0</field> <!-- Disable for tests case -->
</record>
</odoo>
1 change: 1 addition & 0 deletions stock_inventory_discrepancy/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from . import stock_quant
from . import stock_warehouse
from . import stock_location
from . import res_config_settings
38 changes: 38 additions & 0 deletions stock_inventory_discrepancy/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -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",
)
7 changes: 7 additions & 0 deletions stock_inventory_discrepancy/models/stock_quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions stock_inventory_discrepancy/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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).
3 changes: 2 additions & 1 deletion stock_inventory_discrepancy/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Stock Inventory Discrepancy</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:49949b52008fb335a36237b047619ef422c8377d3f70a291232c58658eb31ebd
!! source digest: sha256:34ada4304b49d5c50ece64ebe7599d857948157aaa407477691260ed11341cd1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/stock-logistics-warehouse/tree/16.0/stock_inventory_discrepancy"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-16-0/stock-logistics-warehouse-16-0-stock_inventory_discrepancy"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Adds the capability to show the discrepancy of every line in an inventory and
Expand Down Expand Up @@ -399,6 +399,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<li>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.</li>
</ol>
<p>If necessary, update the “Inventory Discrepancy Control” under “Inventory &gt; Settings” to enable or disable inventory discrepancy (enabled by default).</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
26 changes: 26 additions & 0 deletions stock_inventory_discrepancy/views/res_config_settings_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_stock_config_settings" model="ir.ui.view">
<field name="name">res.config.settings - inventory_discrepancy</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="stock.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[@id='warning_info']" position="after">
<div
class="col-12 col-lg-6 o_setting_box"
id="inventory_discrepancy_enable"
>
<div class="o_setting_left_pane">
<field name="inventory_discrepancy_enable" />
</div>
<div class="o_setting_right_pane">
<label for="inventory_discrepancy_enable" />
<div class="text-muted">
Enable to show line discrepancies in inventory and block validation if the discrepancy exceeds the threshold.
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 726edca

Please sign in to comment.