Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] stock_inventory_discrepancy: add configuration for enabling discrepancy check #1966

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions stock_inventory_discrepancy/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Stock Inventory Discrepancy

|badge1| |badge2| |badge3| |badge4| |badge5|

Adds the capability to show the discrepancy of every line in an inventory and
to block the inventory validation (setting it as 'Pending to Approve') when the
discrepancy is greater than an user defined threshold.
This module adds the capability to show discrepancies for each line in an inventory and
to block inventory validation (setting it as 'Pending to Approve') when the discrepancy
exceeds a user-defined threshold. This is configurable per company through the settings.

Only new group "Validate All inventory Adjustments" will be able to force the
validation of those blocked inventories. By default, Stock manager will belong
Expand All @@ -45,6 +45,7 @@ threshold now.
Configuration
=============

#. Go to "Inventory > Settings" and select the 'Inventory Discrepancy Control' option to block the inventory validation. This should be done for each company.
#. Go to "Inventory > Warehouse Management" > Warehouses" or to "Inventory >
Warehouse Management" > Locations".
#. Modify the "Maximum Discrepancy Rate Threshold" either in a Warehouse or
Expand Down
1 change: 1 addition & 0 deletions stock_inventory_discrepancy/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"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",
],
"license": "AGPL-3",
Expand Down
2 changes: 2 additions & 0 deletions stock_inventory_discrepancy/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import res_company
from . import res_config_settings
from . import stock_quant
from . import stock_warehouse
from . import stock_location
14 changes: 14 additions & 0 deletions stock_inventory_discrepancy/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 Quartile
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

inventory_discrepancy_enable = fields.Boolean(
string="Inventory Discrepancy Control",
help="Block validation of the inventory adjustment if discrepancy exceeds "
"the threshold.",
)
16 changes: 16 additions & 0 deletions stock_inventory_discrepancy/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Quartile
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

inventory_discrepancy_enable = fields.Boolean(
related="company_id.inventory_discrepancy_enable",
readonly=False,
string="Inventory Discrepancy Control",
help="Block validation of the inventory adjustment if discrepancy exceeds "
"the threshold.",
)
2 changes: 2 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,8 @@ 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()
if not self.env.company.inventory_discrepancy_enable:
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
1 change: 1 addition & 0 deletions stock_inventory_discrepancy/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#. Go to "Inventory > Settings" and select the 'Inventory Discrepancy Control' option to block the inventory validation. This should be done for each company.
#. Go to "Inventory > Warehouse Management" > Warehouses" or to "Inventory >
Warehouse Management" > Locations".
#. Modify the "Maximum Discrepancy Rate Threshold" either in a Warehouse or
Expand Down
6 changes: 3 additions & 3 deletions stock_inventory_discrepancy/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Adds the capability to show the discrepancy of every line in an inventory and
to block the inventory validation (setting it as 'Pending to Approve') when the
discrepancy is greater than an user defined threshold.
This module adds the capability to show discrepancies for each line in an inventory and
to block inventory validation (setting it as 'Pending to Approve') when the discrepancy
exceeds a user-defined threshold. This is configurable per company through the settings.

Only new group "Validate All inventory Adjustments" will be able to force the
validation of those blocked inventories. By default, Stock manager will belong
Expand Down
18 changes: 8 additions & 10 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 @@ -370,9 +369,9 @@ <h1 class="title">Stock Inventory Discrepancy</h1>
!! source digest: sha256:f641b413629bafcfd49b92f193419c1f3b79b143737dd5c7bad281002266fdd8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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
to block the inventory validation (setting it as ‘Pending to Approve’) when the
discrepancy is greater than an user defined threshold.</p>
<p>This module adds the capability to show discrepancies for each line in an inventory and
to block inventory validation (setting it as ‘Pending to Approve’) when the discrepancy
exceeds a user-defined threshold. This is configurable per company through the settings.</p>
<p>Only new group “Validate All inventory Adjustments” will be able to force the
validation of those blocked inventories. By default, Stock manager will belong
to this group. In addition, Stock Users can validate inventories under the
Expand All @@ -394,6 +393,7 @@ <h1 class="title">Stock Inventory Discrepancy</h1>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<ol class="arabic simple">
<li>Go to “Inventory &gt; Settings” and select the ‘Inventory Discrepancy Control’ option to block the inventory validation. This should be done for each company.</li>
<li>Go to “Inventory &gt; Warehouse Management” &gt; Warehouses” or to “Inventory &gt;
Warehouse Management” &gt; Locations”.</li>
<li>Modify the “Maximum Discrepancy Rate Threshold” either in a Warehouse or
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,7 @@
class TestInventoryDiscrepancy(TransactionCase):
def setUp(self):
super().setUp()
self.env.company.inventory_discrepancy_enable = True
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>
Loading