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

[17.0][MIG] stock_inventory_discrepancy #2064

Merged
merged 23 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
315be0a
[9.0][ADD] stock_inventory_discrepancy (#245)
LoisRForgeFlow Feb 17, 2017
f335066
[10.0][MIG] stock_inventory_discrepancy
LoisRForgeFlow Aug 23, 2017
a95cb57
[MIG] stock_inventory_discrepancy: Migration to 11.0
Apr 20, 2018
a26a0e5
[10.0][FIX] stock_inventory_discrepancy: Launch wizard as current user
rousseldenis Aug 24, 2018
a72fa96
[12.0][MIG] stock_inventory_discrepancy: Migration to 12.0
Jun 21, 2019
f20c178
[IMP] stock_inventory_discrepancy: black, isort
HviorForgeFlow Jan 7, 2020
3e52938
[MIG] stock_inventory_discrepancy: Migration to 13.0
HviorForgeFlow Jan 7, 2020
17e255b
[UPD] Eficent -> ForgeFlow
MiquelRForgeFlow Sep 30, 2020
dff07a1
[IMP] stock_inventory_discrepancy: centralize logic for over discrepa…
LoisRForgeFlow May 27, 2021
0e11394
[14.0][MIG] stock_inventory_discrepancy: black, isort, prettier
MateuGForgeFlow Sep 9, 2021
d18e997
[14.0][MIG] stock_inventory_discrepancy: Migration to 14.0
MateuGForgeFlow Sep 9, 2021
cc7d5ed
[imp] discrpency by product avg
dnplkndll Nov 18, 2021
b5ab9f9
[REF] stock_inventory_discrepancy: fix eslint no-param-reassign
dreispt Nov 18, 2022
a36c481
[MIG] stock_inventory_discrepancy: Migration to 15.0
Apr 5, 2023
1fd63ee
[FIX] stock_inventory_discrepancy: Ensure active_ids value
pedrobaeza Jun 16, 2023
2d7c6b1
[MIG] stock_inventory_discrepancy: Migration to 16.0
carolinafernandez-tecnativa Sep 18, 2023
b3e04a1
[UPD] Update stock_inventory_discrepancy.pot
Sep 27, 2023
ed36840
[BOT] post-merge updates
OCA-git-bot Sep 27, 2023
89f2e7c
Update translation files
weblate Oct 9, 2023
13165af
Translated using Weblate (Italian)
mymage Nov 21, 2023
ed82e29
Translated using Weblate (Italian)
mymage Nov 21, 2023
b149d75
[IMP] stock_inventory_discrepancy: black, isort, prettier
JasminSForgeFlow Jun 6, 2024
f7791be
[MIG] stock_inventory_discrepancy: Migration to 17.0
JasminSForgeFlow Jun 7, 2024
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
113 changes: 113 additions & 0 deletions stock_inventory_discrepancy/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
===========================
Stock Inventory Discrepancy
===========================

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

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-warehouse/tree/17.0/stock_inventory_discrepancy
:alt: OCA/stock-logistics-warehouse
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-17-0/stock-logistics-warehouse-17-0-stock_inventory_discrepancy
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=17.0
:alt: Try me on Runboat

|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.

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 threshold now.

**Table of contents**

.. contents::
:local:

Configuration
=============

1. Go to "Inventory > Warehouse Management" > Warehouses" or to
"Inventory > Warehouse Management" > Locations".
2. 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.

Usage
=====

If you configured a "Maximum Discrepancy Rate Threshold".

1. When validating an Inventory Adjustment if some line exceed the
Discrepancy Threshold the system will set the inventory's state to
'Pending to Approve' and show the quantity of lines that exceed the
threshold.
2. If both WH and location thresholds are configured, the location one
has preference.
3. The user with "Validate All inventory Adjustments" rights can force
the validation of an inventory pending to approve.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_inventory_discrepancy%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ForgeFlow

Contributors
------------

- Lois Rilo <lois.rilo@forgeflow.com>
- Andreas Dian Sukarno Putro <andreasdian777@gmail.com>
- Bhavesh Odedra <bodedra@opensourceintegrators.com>
- Héctor Villarreal <hector.villarreal@forgeflow.com>
- `Tecnativa <https://www.tecnativa.com>`__:

- Ernesto Tejeda
- Carolina Fernandez

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/17.0/stock_inventory_discrepancy>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions stock_inventory_discrepancy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import models
from . import wizards
from .hooks import post_load_hook
26 changes: 26 additions & 0 deletions stock_inventory_discrepancy/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2017-2024 ForgeFlow S.L. (http://www.forgeflow.com)
# Copyright 2023 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Stock Inventory Discrepancy",
"summary": "Adds the capability to show the discrepancy of every line in "
"an inventory and to block the inventory validation when the "
"discrepancy is over a user defined threshold.",
"version": "17.0.1.0.0",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse",
"depends": ["stock"],
"data": [
"security/stock_inventory_discrepancy_security.xml",
"security/ir.model.access.csv",
"views/stock_quant_view.xml",
"views/stock_warehouse_view.xml",
"views/stock_location_view.xml",
"wizards/confirm_discrepancy_wiz.xml",
],
"license": "AGPL-3",
"post_load": "post_load_hook",
"installable": True,
"application": False,
}
78 changes: 78 additions & 0 deletions stock_inventory_discrepancy/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2019 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).


from odoo import _, fields
from odoo.exceptions import UserError
from odoo.tools.float_utils import float_compare

from odoo.addons.stock.models.stock_quant import StockQuant


def post_load_hook():
def _apply_inventory_discrepancy(self):
"""Override method to avoid inline group validation"""
move_vals = []
# START HOOK: - Allow specific group to validate inventory
# - Allow validate on pending status
if (
not self.user_has_groups("stock.group_stock_manager")
and not self.user_has_groups(
"stock_inventory_discrepancy.group_stock_inventory_validation"
)
and not self.user_has_groups(
"stock_inventory_discrepancy.group_stock_inventory_validation_always"
)
):
raise UserError(

Check warning on line 27 in stock_inventory_discrepancy/hooks.py

View check run for this annotation

Codecov / codecov/patch

stock_inventory_discrepancy/hooks.py#L27

Added line #L27 was not covered by tests
_("Only a stock manager can validate an inventory adjustment.")
)
# Allow to write last_inventory_date on stock.location
self = self.sudo()
# END HOOK
for quant in self:
# Create and validate a move so that the
# quant matches its `inventory_quantity`.
if (
float_compare(
quant.inventory_diff_quantity,
0,
precision_rounding=quant.product_uom_id.rounding,
)
> 0
):
move_vals.append(
quant._get_inventory_move_values(
quant.inventory_diff_quantity,
quant.product_id.with_company(
quant.company_id
).property_stock_inventory,
quant.location_id,
package_dest_id=quant.package_id,
)
)
else:
move_vals.append(

Check warning on line 55 in stock_inventory_discrepancy/hooks.py

View check run for this annotation

Codecov / codecov/patch

stock_inventory_discrepancy/hooks.py#L55

Added line #L55 was not covered by tests
quant._get_inventory_move_values(
-quant.inventory_diff_quantity,
quant.location_id,
quant.product_id.with_company(
quant.company_id
).property_stock_inventory,
package_id=quant.package_id,
)
)
moves = (
self.env["stock.move"].with_context(inventory_mode=False).create(move_vals)
)
moves._action_done()
self.location_id.write({"last_inventory_date": fields.Date.today()})
date_by_location = {
loc: loc._get_next_inventory_date() for loc in self.mapped("location_id")
}
for quant in self:
quant.inventory_date = date_by_location[quant.location_id]
self.write({"inventory_quantity": 0, "user_id": False})
self.write({"inventory_diff_quantity": 0})

StockQuant._apply_inventory = _apply_inventory_discrepancy
Loading
Loading