<commit_before>##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################

from odoo import models, api, _
from odoo.exceptions import ValidationError


class StockMove(models.Model):
    _inherit = 'stock.move'

    @api.constrains('state', 'location_id', 'location_dest_id')
    def check_user_location_rights(self):
        moves = self.filtered(lambda x: x.state != 'draft')
        if not moves or not self.env.user.restrict_locations:
            return True
        user_locations = self.env.user.stock_location_ids
        for user_location in user_locations:
            location = user_locations.search(
                [('id', 'child_of', user_location.id)])
            user_locations |= location
        message = _(
            'Invalid Location. You cannot process this move since you do '
            'not control the location "%s".')
        for rec in moves:
            if rec.location_id not in user_locations:
                raise ValidationError(message % rec.location_id.name)
            elif rec.location_dest_id not in user_locations:
                raise ValidationError(message % rec.location_dest_id.name)<commit_msg>[13.0] [FIX] location_security: Only restrict when you try to validate a pick.<commit_after>##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################

from odoo import models, api, _
from odoo.exceptions import ValidationError


class StockMove(models.Model):
    _inherit = 'stock.move'

    @api.constrains('state', 'location_id', 'location_dest_id')
    def check_user_location_rights(self):
        moves = self.filtered(lambda x: x.state in ['done', 'cancel'])
        if not moves or not self.env.user.restrict_locations:
            return True
        user_locations = self.env.user.stock_location_ids
        for user_location in user_locations:
            location = user_locations.search(
                [('id', 'child_of', user_location.id)])
            user_locations |= location
        message = _(
            'Invalid Location. You cannot process this move since you do '
            'not control the location "%s".')
        for rec in moves:
            if rec.location_id not in user_locations:
                raise ValidationError(message % rec.location_id.name)
            elif rec.location_dest_id not in user_locations:
                raise ValidationError(message % rec.location_dest_id.name)
{'fraction_non_alphanumeric': 0.18704512372634644, 'fraction_numerical': 0.001091703056768559, 'mean_word_length': 3.12143928035982, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6186709', 'n_tokens_mistral': 717, 'n_tokens_neox': 665, 'n_words': 200}