added option to expand sub-storage stocks to display all components from sub_storages
this comes in handy for assortment boxes using sub storages for each individual compartment which usually only holds a single stock
This commit is contained in:
@@ -74,7 +74,13 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
||||
return crumbs
|
||||
|
||||
def search_stock_queryset(self, search):
|
||||
stocks_in_storage = Stock.objects.filter(storage=self.object).order_by(Lower('component__name'))
|
||||
|
||||
if self.object.expand_sub_storage_stocks:
|
||||
stocks_in_storage = Stock.objects.filter(storage__in=self.object.get_tree())
|
||||
else:
|
||||
stocks_in_storage = Stock.objects.filter(storage=self.object)
|
||||
|
||||
stocks_in_storage = stocks_in_storage.order_by(Lower('component__name'))
|
||||
|
||||
if search is None or search == '':
|
||||
return stocks_in_storage
|
||||
@@ -139,6 +145,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
||||
verbose_name=f.cleaned_data.get('verbose_name'),
|
||||
parent_storage=self.object,
|
||||
responsible=f.cleaned_data['responsible'],
|
||||
expand_sub_storage_stocks=f.cleaned_data['expand_sub_storage_stocks'],
|
||||
is_template=f.cleaned_data['is_template'],
|
||||
template=f.cleaned_data.get('template'))
|
||||
except ValidationError as v_err:
|
||||
@@ -154,6 +161,7 @@ class StockViewDetail(LoginRequiredMixin, BaseTemplateMixin, DetailView):
|
||||
self.object.name = f.cleaned_data['storage_name']
|
||||
self.object.verbose_name = f.cleaned_data.get('verbose_name')
|
||||
self.object.responsible = f.cleaned_data['responsible']
|
||||
self.object.expand_sub_storage_stocks = f.cleaned_data['expand_sub_storage_stocks']
|
||||
self.object.is_template = f.cleaned_data['is_template']
|
||||
self.object.save()
|
||||
except ValidationError as v_err:
|
||||
|
Reference in New Issue
Block a user