mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-05 13:10:57 +00:00
Refactor "ownership" concepts in templates
- Template code was very messy - Makes it a lot "simpler" - Adds convenience functions to the StockLocation model - Adds pre-calculated data to the template - Display ownership information on the stocklocation page
This commit is contained in:
@ -63,6 +63,11 @@ class StockIndex(InvenTreeRoleMixin, ListView):
|
||||
context['loc_count'] = StockLocation.objects.count()
|
||||
context['stock_count'] = StockItem.objects.count()
|
||||
|
||||
# No 'ownership' checks are necessary for the top-level StockLocation view
|
||||
context['user_owns_location'] = True
|
||||
context['location_owner'] = None
|
||||
context['ownership_enabled'] = common.models.InvenTreeSetting.get_setting('STOCK_OWNERSHIP_CONTROL')
|
||||
|
||||
return context
|
||||
|
||||
|
||||
@ -76,6 +81,16 @@ class StockLocationDetail(InvenTreeRoleMixin, DetailView):
|
||||
queryset = StockLocation.objects.all()
|
||||
model = StockLocation
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context['ownership_enabled'] = common.models.InvenTreeSetting.get_setting('STOCK_OWNERSHIP_CONTROL')
|
||||
context['location_owner'] = context['location'].get_location_owner()
|
||||
context['user_owns_location'] = context['location'].check_ownership(self.request.user)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class StockItemDetail(InvenTreeRoleMixin, DetailView):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user