Files
Guewen Baconnier 694e2852f5 Remove _order override in stock.location
The default order of stock.location is 'complete_name'.
Changing it to "name" can have side effects, and shouldn't be required
for stock_inventory_lockdown.

See https://github.com/OCA/stock-logistics-warehouse/pull/811/files#r512797834
2022-10-24 10:36:27 -04:00

31 lines
1.1 KiB
Python

# © 2016 Numérigraphe SARL
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, api, models
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"].sudo()._get_locations_open_inventories(vals)
)
if location_inventory_open_ids:
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)
)
if location_inventory_open_ids:
raise ValidationError(_("An inventory is being conducted at this location"))
return super(StockLocation, self).unlink()