diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py
index 42cc5b9f7a..83e7a0db8d 100644
--- a/InvenTree/stock/models.py
+++ b/InvenTree/stock/models.py
@@ -63,6 +63,43 @@ class StockLocation(InvenTreeTree):
help_text=_('Select Owner'),
related_name='stock_locations')
+ def get_location_owner(self):
+ """
+ Get the closest "owner" for this location.
+
+ Start at this location, and traverse "up" the location tree until we find an owner
+ """
+
+ for loc in self.get_ancestors(include_self=True, ascending=True):
+ if loc.owner is not None:
+ return loc.owner
+
+ return None
+
+ def check_ownership(self, user):
+ """
+ Check if the user "owns" (is one of the owners of) the location.
+ """
+
+ # Superuser accounts automatically "own" everything
+ if user.is_superuser:
+ return True
+
+ ownership_enabled = common.models.InvenTreeSetting.get_setting('STOCK_OWNERSHIP_CONTROL')
+
+ if not ownership_enabled:
+ # Location ownership function is not enabled, so return True
+ return True
+
+ owner = self.get_location_owner()
+
+ if owner is None:
+ # No owner set, for this location or any location above
+ # So, no ownership checks to perform!
+ return True
+
+ return user in owner.get_related_owners(include_group=True)
+
def get_absolute_url(self):
return reverse('stock-location-detail', kwargs={'pk': self.id})
diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html
index c07e4f8162..68a4cd7aed 100644
--- a/InvenTree/stock/templates/stock/location.html
+++ b/InvenTree/stock/templates/stock/location.html
@@ -20,7 +20,6 @@
{% endblock %}
{% block actions %}
-{% setting_object 'STOCK_OWNERSHIP_CONTROL' as owner_control %}
{% if location and user.is_staff and roles.stock_location.change %}
@@ -40,7 +39,7 @@
-{% if owner_control.value == "False" or owner_control.value == "True" and user in owners or user.is_superuser %}
+{% if user_owns_location %}
{% if roles.stock.change %}