diff --git a/stock_inventory_lockdown/README.rst b/stock_inventory_lockdown/README.rst index 4d61c6d69..2acf8af38 100644 --- a/stock_inventory_lockdown/README.rst +++ b/stock_inventory_lockdown/README.rst @@ -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 =========== diff --git a/stock_inventory_lockdown/__openerp__.py b/stock_inventory_lockdown/__manifest__.py similarity index 81% rename from stock_inventory_lockdown/__openerp__.py rename to stock_inventory_lockdown/__manifest__.py index 6e5205497..3196028d1 100644 --- a/stock_inventory_lockdown/__openerp__.py +++ b/stock_inventory_lockdown/__manifest__.py @@ -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", diff --git a/stock_inventory_lockdown/models/stock_inventory.py b/stock_inventory_lockdown/models/stock_inventory.py index 8839115be..aab5010fd 100644 --- a/stock_inventory_lockdown/models/stock_inventory.py +++ b/stock_inventory_lockdown/models/stock_inventory.py @@ -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): diff --git a/stock_inventory_lockdown/models/stock_location.py b/stock_inventory_lockdown/models/stock_location.py index 574ac2866..62662d4d8 100644 --- a/stock_inventory_lockdown/models/stock_location.py +++ b/stock_inventory_lockdown/models/stock_location.py @@ -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() diff --git a/stock_inventory_lockdown/models/stock_move.py b/stock_inventory_lockdown/models/stock_move.py index d5ffdfb7f..fbc1f2161 100644 --- a/stock_inventory_lockdown/models/stock_move.py +++ b/stock_inventory_lockdown/models/stock_move.py @@ -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]) diff --git a/stock_inventory_lockdown/static/description/icon.png b/stock_inventory_lockdown/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_inventory_lockdown/static/description/icon.png differ diff --git a/stock_inventory_lockdown/images/move_error.png b/stock_inventory_lockdown/static/images/move_error.png similarity index 100% rename from stock_inventory_lockdown/images/move_error.png rename to stock_inventory_lockdown/static/images/move_error.png diff --git a/stock_inventory_lockdown/tests/test_stock_inventory_lockdown.py b/stock_inventory_lockdown/tests/test_stock_inventory_lockdown.py index cfcb7dfeb..60e7c8785 100644 --- a/stock_inventory_lockdown/tests/test_stock_inventory_lockdown.py +++ b/stock_inventory_lockdown/tests/test_stock_inventory_lockdown.py @@ -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')