mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Abstract template context data for part
This commit is contained in:
parent
edb803bf67
commit
15a59d54ca
@ -717,6 +717,7 @@ input[type="submit"] {
|
||||
right: 0px;
|
||||
top: 70px;
|
||||
position: sticky;
|
||||
font-size: 115%;
|
||||
}
|
||||
|
||||
.sidenav-right svg {
|
||||
|
@ -325,6 +325,35 @@ class Part(MPTTModel):
|
||||
# For legacy reasons the 'variant_of' field is used to indicate the MPTT parent
|
||||
parent_attr = 'variant_of'
|
||||
|
||||
def get_context_data(self, request, **kwargs):
|
||||
"""
|
||||
Return some useful context data about this part for template rendering
|
||||
"""
|
||||
|
||||
context = {}
|
||||
|
||||
context['starred'] = self.isStarredBy(request.user)
|
||||
context['disabled'] = not self.active
|
||||
|
||||
# Pre-calculate complex queries so they only need to be performed once
|
||||
context['total_stock'] = self.total_stock
|
||||
|
||||
context['quantity_being_built'] = self.quantity_being_built
|
||||
|
||||
context['required_build_order_quantity'] = self.required_build_order_quantity()
|
||||
context['allocated_build_order_quantity'] = self.build_order_allocation_count()
|
||||
|
||||
context['required_sales_order_quantity'] = self.required_sales_order_quantity()
|
||||
context['allocated_sales_order_quantity'] = self.sales_order_allocation_count()
|
||||
|
||||
context['available'] = self.available_stock
|
||||
context['on_order'] = self.on_order
|
||||
|
||||
context['required'] = context['required_build_order_quantity'] + context['required_sales_order_quantity']
|
||||
context['allocated'] = context['allocated_build_order_quantity'] + context['allocated_sales_order_quantity']
|
||||
|
||||
return context
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""
|
||||
Overrides the save() function for the Part model.
|
||||
|
@ -753,14 +753,15 @@ class PartNotes(UpdateView):
|
||||
|
||||
part = self.get_object()
|
||||
|
||||
ctx = super().get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
ctx['editing'] = str2bool(self.request.GET.get('edit', ''))
|
||||
context['editing'] = str2bool(self.request.GET.get('edit', ''))
|
||||
|
||||
ctx['starred'] = part.isStarredBy(self.request.user)
|
||||
ctx['disabled'] = not part.active
|
||||
ctx = part.get_context_data(self.request)
|
||||
|
||||
return ctx
|
||||
context.update(ctx)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class PartDetail(InvenTreeRoleMixin, DetailView):
|
||||
@ -779,7 +780,7 @@ class PartDetail(InvenTreeRoleMixin, DetailView):
|
||||
|
||||
- If '?editing=True', set 'editing_enabled' context variable
|
||||
"""
|
||||
context = super(PartDetail, self).get_context_data(**kwargs)
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
part = self.get_object()
|
||||
|
||||
@ -789,24 +790,8 @@ class PartDetail(InvenTreeRoleMixin, DetailView):
|
||||
else:
|
||||
context['editing_enabled'] = 0
|
||||
|
||||
context['starred'] = part.isStarredBy(self.request.user)
|
||||
context['disabled'] = not part.active
|
||||
|
||||
# Pre-calculate complex queries so they only need to be performed once
|
||||
context['total_stock'] = part.total_stock
|
||||
|
||||
context['quantity_being_built'] = part.quantity_being_built
|
||||
|
||||
context['required_build_order_quantity'] = part.required_build_order_quantity()
|
||||
context['allocated_build_order_quantity'] = part.build_order_allocation_count()
|
||||
|
||||
context['required_sales_order_quantity'] = part.required_sales_order_quantity()
|
||||
context['allocated_sales_order_quantity'] = part.sales_order_allocation_count()
|
||||
|
||||
context['available'] = part.available_stock
|
||||
context['on_order'] = part.on_order
|
||||
context['required'] = context['required_build_order_quantity'] + context['required_sales_order_quantity']
|
||||
context['allocated'] = context['allocated_build_order_quantity'] + context['allocated_sales_order_quantity']
|
||||
ctx = part.get_context_data(self.request)
|
||||
context.update(**ctx)
|
||||
|
||||
return context
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user