Skip to content

Commit 822fb65

Browse files
[ADD] stock_inventory_lockdown_product in v15
1 parent 196766b commit 822fb65

File tree

18 files changed

+791
-0
lines changed

18 files changed

+791
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../stock_inventory_lockdown_product
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
===========================
2+
Inventory Lock Down Product
3+
===========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:d2260a9994d247c2bc17d41f6c2e61390e016b5cf48b1dd871614c1a02824a1a
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github
20+
:target: https://github.com/OCA/stock-logistics-warehouse/tree/15.0/stock_inventory_lockdown_product
21+
:alt: OCA/stock-logistics-warehouse
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-15-0/stock-logistics-warehouse-15-0-stock_inventory_lockdown_product
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=15.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
By default, stock_inventory_lockdown blocks any stock movement to or from locations
32+
involved in an in-progress inventory adjustment.
33+
34+
With this module installed and enabled, the restriction becomes product-aware if
35+
you activate a setting.
36+
37+
In Configuration / Settings mark the option to use a soft lockdown in the company
38+
39+
**Table of contents**
40+
41+
.. contents::
42+
:local:
43+
44+
Usage
45+
=====
46+
47+
Stock moves to or from locations involved in open inventory adjustments will only be blocked if the moved product is also listed in the adjustment.
48+
49+
Bug Tracker
50+
===========
51+
52+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
53+
In case of trouble, please check there if your issue has already been reported.
54+
If you spotted it first, help us to smash it by providing a detailed and welcomed
55+
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_inventory_lockdown_product%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
56+
57+
Do not contact contributors directly about support or help with technical issues.
58+
59+
Credits
60+
=======
61+
62+
Authors
63+
~~~~~~~
64+
65+
* ForgeFlow
66+
67+
Contributors
68+
~~~~~~~~~~~~
69+
70+
* Aaron Henriquez <aaron.henriquez@forgeflow.com>
71+
72+
Maintainers
73+
~~~~~~~~~~~
74+
75+
This module is maintained by the OCA.
76+
77+
.. image:: https://odoo-community.org/logo.png
78+
:alt: Odoo Community Association
79+
:target: https://odoo-community.org
80+
81+
OCA, or the Odoo Community Association, is a nonprofit organization whose
82+
mission is to support the collaborative development of Odoo features and
83+
promote its widespread use.
84+
85+
This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/15.0/stock_inventory_lockdown_product>`_ project on GitHub.
86+
87+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2025 ForgeFlow SL
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
{
5+
"name": "Inventory Lock Down Product",
6+
"summary": "Lock down stock locations during inventories for inventoried products",
7+
"version": "15.0.1.0.0",
8+
"development_status": "Beta",
9+
"depends": ["stock_inventory_lockdown"],
10+
"author": "ForgeFlow, Odoo Community Association (OCA)",
11+
"website": "https://github.com/OCA/stock-logistics-warehouse",
12+
"category": "Warehouse Management",
13+
"license": "AGPL-3",
14+
"data": ["views/res_config_settings_view.xml"],
15+
"installable": True,
16+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from . import res_company
2+
from . import res_config_settings
3+
from . import stock_move_line
4+
from . import stock_inventory
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2025 ForgeFlow S.L. (http://www.forgeflow.com)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResCompany(models.Model):
8+
_inherit = "res.company"
9+
10+
use_soft_inventory_lock = fields.Boolean(
11+
string="Use Product-Aware Inventory Lock",
12+
help="When enabled, only restrict stock moves if "
13+
"the product is part of an ongoing inventory adjustment at the location.",
14+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2025 ForgeFlow S.L. (http://www.forgeflow.com)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResConfigSettings(models.TransientModel):
8+
_inherit = "res.config.settings"
9+
10+
use_soft_inventory_lock = fields.Boolean(
11+
related="company_id.use_soft_inventory_lock", readonly=False
12+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2025 ForgeFlow S.L. (http://www.forgeflow.com)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
from odoo import api, models
4+
5+
6+
class StockInventory(models.Model):
7+
_inherit = "stock.inventory"
8+
9+
@api.model
10+
def _get_open_inventories_by_locations(self, location_ids=None):
11+
if not location_ids:
12+
return self.env["stock.inventory"]
13+
14+
inventory_domain_same_location = [
15+
("state", "=", "in_progress"),
16+
("location_ids", "in", location_ids),
17+
]
18+
inventories_same_location = self.search(inventory_domain_same_location)
19+
20+
inventory_domain_parent = [
21+
("state", "=", "in_progress"),
22+
("exclude_sublocation", "=", False),
23+
]
24+
inventories_possible_parent = self.search(inventory_domain_parent)
25+
inventories_parent = self.env["stock.inventory"]
26+
27+
for inventory in inventories_possible_parent:
28+
for location in inventory.location_ids:
29+
if any(
30+
loc_id in location.child_internal_location_ids.ids
31+
for loc_id in location_ids
32+
):
33+
inventories_parent |= inventory
34+
35+
return inventories_same_location | inventories_parent
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2025 ForgeFlow S.L. (http://www.forgeflow.com)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
from odoo import _, api, models
5+
from odoo.exceptions import ValidationError
6+
7+
8+
class StockMoveLine(models.Model):
9+
_inherit = "stock.move.line"
10+
11+
@api.constrains("location_dest_id", "location_id", "state")
12+
def _check_locked_location(self):
13+
if not self.company_id.use_soft_inventory_lock:
14+
return super()._check_locked_location()
15+
16+
for move_line in self.filtered(lambda m: m.state == "done"):
17+
inventories = self.env[
18+
"stock.inventory"
19+
]._get_open_inventories_by_locations(
20+
[move_line.location_dest_id.id, move_line.location_id.id]
21+
)
22+
for inventory in inventories:
23+
inventory_products = inventory.stock_quant_ids.mapped("product_id.id")
24+
if move_line.product_id.id in inventory_products:
25+
if not self._location_usage_without_restriction(move_line):
26+
location_names = inventory.location_ids.mapped("complete_name")
27+
msg = _(
28+
"Inventory adjustment underway at the following location(s):\n"
29+
"- %(locations)s\n"
30+
"Product '%(product)s' is included in the inventory. "
31+
"Moving it to/from these locations is not allowed until the "
32+
"adjustment is complete."
33+
) % {
34+
"locations": "\n - ".join(location_names),
35+
"product": move_line.product_id.display_name,
36+
}
37+
raise ValidationError(msg)

0 commit comments

Comments
 (0)