mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
stock_inventory_lockdown
This commit is contained in:
@@ -10,20 +10,17 @@ This module lets you lock down the locations during an inventory.
|
||||
Usage
|
||||
=====
|
||||
|
||||
.. image:: images/location_locked.png
|
||||
:alt: Error message
|
||||
|
||||
.. image:: images/move_error.png
|
||||
:alt: Error message
|
||||
|
||||
While an inventory is in the state "In progress", no stock moves
|
||||
can be recorded in/out of the inventory's location: users will get an error
|
||||
message.
|
||||
Creating or modifying a locations is also forbidden.
|
||||
Creating or modifying locations is also forbidden.
|
||||
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
:alt: Try me on Runbot
|
||||
:target: https://runbot.odoo-community.org/runbot/153/8.0
|
||||
:target: https://runbot.odoo-community.org/runbot/153/9.0
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
@@ -31,11 +28,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 smashing it by providing a detailed and welcomed `feedback
|
||||
<https://github.com/OCA/
|
||||
stock-logistics-warehouse/issues/new?body=module:%20
|
||||
stock_available_sale%0Aversion:%20
|
||||
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
help us smashing it by providing a detailed and welcomed feedback.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
"name": "Inventory lock down",
|
||||
"name": "Inventory Lock Down",
|
||||
"summary": "Lock down stock locations during inventories.",
|
||||
"version": "8.0.1.0.0",
|
||||
"version": "9.0.1.0.0",
|
||||
"depends": ["stock"],
|
||||
"author": u"Numérigraphe,Odoo Community Association (OCA)",
|
||||
"author": "Numérigraphe,Odoo Community Association (OCA)",
|
||||
"category": "Warehouse Management",
|
||||
"images": [
|
||||
"images/move_error.png",
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 13 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 11 KiB |
@@ -9,18 +9,24 @@ class StockInventory(models.Model):
|
||||
_inherit = 'stock.inventory'
|
||||
|
||||
@api.model
|
||||
def _get_locations_open_inventories(self):
|
||||
"""IDs of location in open exhaustive inventories, with children"""
|
||||
inventories = self.search([('state', '=', 'confirm')])
|
||||
def _get_locations_open_inventories(self, locations_ids=None):
|
||||
"""IDs of locations in open exhaustive inventories, with children"""
|
||||
inventory_domain = [('state', '=', 'confirm')]
|
||||
if locations_ids:
|
||||
inventory_domain.append(('location_id', 'child_of', locations_ids))
|
||||
inventories = self.search(inventory_domain)
|
||||
if not inventories:
|
||||
# Early exit if no match found
|
||||
return []
|
||||
location_ids = inventories.mapped('location_id')
|
||||
|
||||
# Extend to the children Locations
|
||||
return self.env['stock.location'].search(
|
||||
[('location_id', 'child_of', location_ids.ids),
|
||||
('usage', 'in', ['internal', 'transit'])])
|
||||
location_domain = [
|
||||
('location_id', 'child_of', location_ids.ids),
|
||||
('usage', 'in', ['internal', 'transit'])]
|
||||
if locations_ids:
|
||||
location_domain.append(('location_id', 'child_of', locations_ids))
|
||||
return self.env['stock.location'].search(location_domain)
|
||||
|
||||
@api.multi
|
||||
def action_done(self):
|
||||
|
||||
@@ -14,13 +14,12 @@ class StockLocation(models.Model):
|
||||
@api.multi
|
||||
def _check_inventory(self):
|
||||
"""Error if an inventory is being conducted here"""
|
||||
location_inventory_open_ids = self.env['stock.inventory'].sudo(
|
||||
)._get_locations_open_inventories()
|
||||
for location in self:
|
||||
if location in location_inventory_open_ids:
|
||||
raise ValidationError(
|
||||
_('An inventory is being conducted at this '
|
||||
'location'))
|
||||
location_inventory_open_ids = self.env['stock.inventory'].sudo().\
|
||||
_get_locations_open_inventories(self.ids)
|
||||
if location_inventory_open_ids:
|
||||
raise ValidationError(
|
||||
_('An inventory is being conducted at this '
|
||||
'location'))
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
|
||||
@@ -20,26 +20,19 @@ class StockQuant(models.Model):
|
||||
"""
|
||||
if not self.env.context.get('bypass_lockdown', False):
|
||||
# Find the locked locations
|
||||
locked_location_ids = self.env[
|
||||
'stock.inventory']._get_locations_open_inventories()
|
||||
if locked_location_ids and 'location_id' in vals.keys():
|
||||
messages = set()
|
||||
# Find the destination locations
|
||||
location_dest_id = self.env['stock.location'].browse(
|
||||
vals['location_id'])
|
||||
for quant in self:
|
||||
# Source locations
|
||||
location_id = quant.location_id
|
||||
# Moving to a location locked down
|
||||
if location_dest_id in locked_location_ids:
|
||||
messages.add(location_dest_id.name)
|
||||
# Moving from a location locked down
|
||||
if location_id in locked_location_ids:
|
||||
messages.add(location_id.name)
|
||||
if len(messages):
|
||||
raise ValidationError(
|
||||
_('An inventory is being conducted at the following '
|
||||
'location(s):\n%s') % "\n - ".join(messages))
|
||||
locked_location_ids = []
|
||||
if 'location_id' in vals.keys():
|
||||
locked_location_ids = self.env[
|
||||
'stock.inventory']._get_locations_open_inventories(
|
||||
self.env['stock.location'].browse(
|
||||
vals['location_id']).ids + self.mapped(
|
||||
'location_id').ids
|
||||
)
|
||||
if locked_location_ids:
|
||||
location_names = locked_location_ids.mapped('name')
|
||||
raise ValidationError(
|
||||
_('An inventory is being conducted at the following '
|
||||
'location(s):\n%s') % "\n - ".join(location_names))
|
||||
return super(StockQuant, self).write(vals)
|
||||
|
||||
@api.model
|
||||
@@ -49,9 +42,9 @@ class StockQuant(models.Model):
|
||||
"""
|
||||
quant = super(StockQuant, self).create(vals)
|
||||
if not self.env.context.get('bypass_lockdown', False):
|
||||
locked_location_ids = self.env[
|
||||
'stock.inventory']._get_locations_open_inventories()
|
||||
if quant.location_id in locked_location_ids:
|
||||
locked_location_ids = self.env['stock.inventory'].\
|
||||
_get_locations_open_inventories(quant.location_id.ids)
|
||||
if locked_location_ids:
|
||||
raise ValidationError(
|
||||
_('An inventory is being conducted at the following '
|
||||
'location(s):\n%s') % " - " + quant.location_id.name)
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from openerp.exceptions import ValidationError
|
||||
|
||||
from openerp.addons.stock.tests.common import TestStockCommon
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user