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;
|
right: 0px;
|
||||||
top: 70px;
|
top: 70px;
|
||||||
position: sticky;
|
position: sticky;
|
||||||
|
font-size: 115%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidenav-right svg {
|
.sidenav-right svg {
|
||||||
|
@ -325,6 +325,35 @@ class Part(MPTTModel):
|
|||||||
# For legacy reasons the 'variant_of' field is used to indicate the MPTT parent
|
# For legacy reasons the 'variant_of' field is used to indicate the MPTT parent
|
||||||
parent_attr = 'variant_of'
|
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):
|
def save(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Overrides the save() function for the Part model.
|
Overrides the save() function for the Part model.
|
||||||
|
@ -753,14 +753,15 @@ class PartNotes(UpdateView):
|
|||||||
|
|
||||||
part = self.get_object()
|
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 = part.get_context_data(self.request)
|
||||||
ctx['disabled'] = not part.active
|
|
||||||
|
|
||||||
return ctx
|
context.update(ctx)
|
||||||
|
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
class PartDetail(InvenTreeRoleMixin, DetailView):
|
class PartDetail(InvenTreeRoleMixin, DetailView):
|
||||||
@ -779,7 +780,7 @@ class PartDetail(InvenTreeRoleMixin, DetailView):
|
|||||||
|
|
||||||
- If '?editing=True', set 'editing_enabled' context variable
|
- 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()
|
part = self.get_object()
|
||||||
|
|
||||||
@ -789,24 +790,8 @@ class PartDetail(InvenTreeRoleMixin, DetailView):
|
|||||||
else:
|
else:
|
||||||
context['editing_enabled'] = 0
|
context['editing_enabled'] = 0
|
||||||
|
|
||||||
context['starred'] = part.isStarredBy(self.request.user)
|
ctx = part.get_context_data(self.request)
|
||||||
context['disabled'] = not part.active
|
context.update(**ctx)
|
||||||
|
|
||||||
# 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']
|
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user