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 Nov 15, 2024
1 parent 1b6ab0b commit d85c615
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 7 deletions.
2 changes: 2 additions & 0 deletions stock_inventory_discrepancy/README.rst
Original file line number Diff line number Diff line change
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="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",
)
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 @@ -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(
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).
12 changes: 5 additions & 7 deletions stock_inventory_discrepancy/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +274,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: gray; } /* line numbers */
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +300,7 @@
span.pre {
white-space: pre }

span.problematic, pre.problematic {
span.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -399,6 +398,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 Expand Up @@ -446,9 +446,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
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">
Block validation of the inventory adjustment if discrepancy exceeds the threshold.
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>

0 comments on commit d85c615

Please sign in to comment.