[MIG] stock_inventory_lockdown: Migration to 10.0

This commit is contained in:
mreficent
2017-07-27 17:29:51 +02:00
committed by Adrià Gil Sorribes
parent b506999f27
commit 006db42afa
8 changed files with 27 additions and 37 deletions

View File

@@ -10,7 +10,7 @@ This module lets you lock down the locations during an inventory.
Usage
=====
.. image:: images/move_error.png
.. image:: stock_inventory_lockdown/static/images/move_error.png
:alt: Error message
While an inventory is in the state "In progress", no stock moves
@@ -20,7 +20,7 @@ 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/9.0
:target: https://runbot.odoo-community.org/runbot/153/10.0
Bug Tracker
===========

View File

@@ -5,9 +5,9 @@
{
"name": "Inventory Lock Down",
"summary": "Lock down stock locations during inventories.",
"version": "9.0.1.0.1",
"version": "10.0.1.0.0",
"depends": ["stock"],
"author": "Numérigraphe,Odoo Community Association (OCA)",
"author": "Numérigraphe,Eficent,Odoo Community Association (OCA)",
"category": "Warehouse Management",
"images": [
"images/move_error.png",

View File

@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
# © 2013-2016 Numérigraphe SARL
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, api
from odoo import api, models
class StockInventory(models.Model):

View File

@@ -2,8 +2,8 @@
# © 2016 Numérigraphe SARL
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, api, _
from openerp.exceptions import ValidationError
from odoo import api, models, _
from odoo.exceptions import ValidationError
class StockLocation(models.Model):
@@ -12,34 +12,22 @@ class StockLocation(models.Model):
_order = 'name'
@api.multi
def _check_inventory(self):
@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'].sudo().\
_get_locations_open_inventories(self.ids)
_get_locations_open_inventories(vals)
if location_inventory_open_ids:
raise ValidationError(
_('An inventory is being conducted at this '
'location'))
@api.multi
def write(self, vals):
"""Refuse write if an inventory is being conducted"""
locations_to_check = self
# If changing the parent, no inventory must conducted there either
if vals.get('location_id'):
locations_to_check |= self.browse(vals['location_id'])
locations_to_check._check_inventory()
return super(StockLocation, self).write(vals)
@api.model
def create(self, vals):
"""Refuse create if an inventory is being conducted at the parent"""
if 'location_id' in vals:
self.browse(vals['location_id'])._check_inventory()
return super(StockLocation, self).create(vals)
_('An inventory is being conducted at this location'))
@api.multi
def unlink(self):
"""Refuse unlink if an inventory is being conducted"""
self._check_inventory()
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'))
return super(StockLocation, self).unlink()

View File

@@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
# © 2016 Numérigraphe SARL
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, api, _
from openerp.exceptions import ValidationError
from odoo import api, models, _
from odoo.exceptions import ValidationError
class StockMove(models.Model):
@@ -11,9 +13,7 @@ class StockMove(models.Model):
@api.constrains('location_dest_id', 'location_id', 'state')
def _check_locked_location(self):
for move in self:
if move.state == 'draft':
continue
for move in self.filtered(lambda m: m.state != 'draft'):
locked_location_ids = self.env[
'stock.inventory']._get_locations_open_inventories(
[move.location_dest_id.id, move.location_id.id])

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -3,8 +3,8 @@
# © 2016 Numérigraphe SARL
# 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
from odoo.exceptions import ValidationError
from odoo.addons.stock.tests.common import TestStockCommon
class StockInventoryLocationTest(TestStockCommon):
@@ -33,7 +33,7 @@ class StockInventoryLocationTest(TestStockCommon):
def test_update_parent_location(self):
"""Updating the parent of a location is OK if no inv. in progress."""
self.inventory.action_cancel_inventory()
self.inventory.action_cancel_draft()
self.inventory.location_id.location_id = self.env.ref(
'stock.stock_location_4')