##############################################################################
# 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):
        if self.env.user.restrict_locations:
            user_locations = self.env.user.stock_location_ids
            message = _(
                'Invalid Location. You cannot process this move since you do '
                'not control the location "%s".')
            for rec in self.filtered(lambda x: x.state != 'draft'):
                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)

@@ -493,18 +493,95 @@
         
-if
+moves = self.filtered(lambda x: x.state != 'draft')%0A        if not moves or not
  self.en
@@ -603,32 +603,52 @@
 _locations:%0A    
+        return True%0A
         user_loc
@@ -689,24 +689,206 @@
 ion_ids%0A    
+    for user_location in user_locations:%0A            location = user_locations.search(%0A                %5B('id', 'child_of', user_location.id)%5D)%0A            user_locations %7C= location%0A
         mess
@@ -896,20 +896,16 @@
 ge = _(%0A
-    
         
@@ -983,20 +983,16 @@
         
-   
- 
 'not con
@@ -1021,28 +1021,24 @@
 .')%0A        
-    
 for rec in s
@@ -1040,57 +1040,15 @@
  in 
-self.filtered(lambda x: x.state != 'draft'):%0A    
+moves:%0A
     
@@ -1105,36 +1105,32 @@
                 
-  
-  
 raise Validation
@@ -1179,20 +1179,16 @@
         
-    
 elif rec
@@ -1220,36 +1220,32 @@
 user_locations:%0A
-    
                 

add to set only de parent and restring the all childs of locations (#163)