mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_inventory_lockdown: refactor in order to block movement in stock.move.line confirmation
This commit is contained in:
@@ -17,13 +17,13 @@ Inventory Lock Down
|
||||
: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/16.0/stock_inventory_lockdown
|
||||
:target: https://github.com/OCA/stock-logistics-warehouse/tree/15.0/stock_inventory_lockdown
|
||||
: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-16-0/stock-logistics-warehouse-16-0-stock_inventory_lockdown
|
||||
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-15-0/stock-logistics-warehouse-15-0-stock_inventory_lockdown
|
||||
: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=16.0
|
||||
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=15.0
|
||||
:alt: Try me on Runboat
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
@@ -43,7 +43,7 @@ can be recorded in/out of the inventory's location: users will get an error
|
||||
message.
|
||||
Creating or modifying locations is also forbidden.
|
||||
|
||||
.. figure:: https://raw.githubusercontent.com/OCA/stock-logistics-warehouse/16.0/stock_inventory_lockdown/static/images/move_error.png
|
||||
.. figure:: https://raw.githubusercontent.com/OCA/stock-logistics-warehouse/15.0/stock_inventory_lockdown/static/images/move_error.png
|
||||
:alt: Error message
|
||||
|
||||
Bug Tracker
|
||||
@@ -52,7 +52,7 @@ 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_lockdown%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_inventory_lockdown%0Aversion:%2015.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.
|
||||
|
||||
@@ -90,6 +90,6 @@ 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/16.0/stock_inventory_lockdown>`_ project on GitHub.
|
||||
This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/15.0/stock_inventory_lockdown>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
from . import stock_move
|
||||
from . import stock_move_line
|
||||
from . import stock_inventory
|
||||
from . import stock_location
|
||||
|
||||
@@ -11,7 +11,6 @@ class StockInventory(models.Model):
|
||||
|
||||
@api.model
|
||||
def _get_locations_open_inventories(self, locations_ids=None):
|
||||
"""IDs of locations in open exhaustive inventories, with children"""
|
||||
inventory_domain = [("state", "=", "in_progress")]
|
||||
if locations_ids:
|
||||
inventory_domain.append(("location_ids", "child_of", locations_ids))
|
||||
@@ -20,7 +19,6 @@ class StockInventory(models.Model):
|
||||
# Early exit if no match found
|
||||
return []
|
||||
location_ids = inventories.mapped("location_ids")
|
||||
|
||||
# Extend to the children Locations
|
||||
location_domain = [
|
||||
"|",
|
||||
|
||||
@@ -6,13 +6,10 @@ from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class StockLocation(models.Model):
|
||||
"""Refuse changes during exhaustive Inventories"""
|
||||
|
||||
_inherit = "stock.location"
|
||||
|
||||
@api.constrains("location_id")
|
||||
def _check_inventory_location_id(self):
|
||||
"""Error if an inventory is being conducted here"""
|
||||
vals = set(self.ids) | set(self.mapped("location_id").ids)
|
||||
location_inventory_open_ids = self.env[
|
||||
"stock.inventory"
|
||||
@@ -21,7 +18,6 @@ class StockLocation(models.Model):
|
||||
raise ValidationError(_("An inventory is being conducted at this location"))
|
||||
|
||||
def unlink(self):
|
||||
"""Refuse unlink if an inventory is being conducted"""
|
||||
location_inventory_open_ids = (
|
||||
self.env["stock.inventory"].sudo()._get_locations_open_inventories(self.ids)
|
||||
)
|
||||
|
||||
@@ -7,8 +7,8 @@ from odoo import _, api, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class StockMove(models.Model):
|
||||
_inherit = "stock.move"
|
||||
class StockMoveLine(models.Model):
|
||||
_inherit = "stock.move.line"
|
||||
|
||||
def _get_reserved_locations(self):
|
||||
self.ensure_one()
|
||||
@@ -20,33 +20,34 @@ class StockMove(models.Model):
|
||||
|
||||
@api.constrains("location_dest_id", "location_id", "state")
|
||||
def _check_locked_location(self):
|
||||
for move in self.filtered(lambda m: m.state != "draft"):
|
||||
for move_line in self.filtered(lambda m: m.state == "done"):
|
||||
locked_location_ids = self.env[
|
||||
"stock.inventory"
|
||||
]._get_locations_open_inventories(
|
||||
[move.location_dest_id.id, move.location_id.id]
|
||||
[move_line.location_dest_id.id, move_line.location_id.id]
|
||||
)
|
||||
reserved_locs = move._get_reserved_locations()
|
||||
dest_locs = move._get_dest_locations()
|
||||
reserved_origin_loc = move_line.location_id
|
||||
dest_loc = move_line.location_dest_id
|
||||
if (
|
||||
locked_location_ids
|
||||
and not any(
|
||||
[
|
||||
move.location_dest_id.usage == "inventory",
|
||||
move.location_id.usage == "inventory",
|
||||
move_line.location_dest_id.usage == "inventory",
|
||||
move_line.location_id.usage == "inventory",
|
||||
]
|
||||
)
|
||||
and (
|
||||
move.location_dest_id in locked_location_ids
|
||||
or any([loc in locked_location_ids for loc in dest_locs])
|
||||
or any([loc in locked_location_ids for loc in reserved_locs])
|
||||
reserved_origin_loc in locked_location_ids
|
||||
or dest_loc in locked_location_ids
|
||||
)
|
||||
):
|
||||
location_names = locked_location_ids.mapped("complete_name")
|
||||
raise ValidationError(
|
||||
_(
|
||||
"An inventory is being conducted at the following "
|
||||
"location(s):\n - %s"
|
||||
"Inventory adjusment underway at "
|
||||
"the following location(s):\n- %s\n"
|
||||
"Moving products to or from these locations is "
|
||||
"not allowed until the inventory check is complete."
|
||||
)
|
||||
% "\n - ".join(location_names)
|
||||
)
|
||||
@@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
@@ -369,7 +368,7 @@ ul.auto-toc {
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! source digest: sha256:babaf62e88e317c7456236551ea3ca7c5620730997acea8fbf6e8c4fa3c9ccc0
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<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_lockdown"><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_lockdown"><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&target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
|
||||
<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/15.0/stock_inventory_lockdown"><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-15-0/stock-logistics-warehouse-15-0-stock_inventory_lockdown"><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&target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
|
||||
<p>This module lets you lock down the locations during an inventory.</p>
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
@@ -391,7 +390,7 @@ can be recorded in/out of the inventory’s location: users will get an error
|
||||
message.
|
||||
Creating or modifying locations is also forbidden.</p>
|
||||
<div class="figure">
|
||||
<img alt="Error message" src="https://raw.githubusercontent.com/OCA/stock-logistics-warehouse/16.0/stock_inventory_lockdown/static/images/move_error.png" />
|
||||
<img alt="Error message" src="https://raw.githubusercontent.com/OCA/stock-logistics-warehouse/15.0/stock_inventory_lockdown/static/images/move_error.png" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
@@ -399,7 +398,7 @@ Creating or modifying locations is also forbidden.</p>
|
||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues">GitHub Issues</a>.
|
||||
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
|
||||
<a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_inventory_lockdown%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_inventory_lockdown%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||
</div>
|
||||
<div class="section" id="credits">
|
||||
@@ -431,7 +430,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
|
||||
<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>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/16.0/stock_inventory_lockdown">OCA/stock-logistics-warehouse</a> project on GitHub.</p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/15.0/stock_inventory_lockdown">OCA/stock-logistics-warehouse</a> project on GitHub.</p>
|
||||
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user