mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
82 lines
2.2 KiB
Python
82 lines
2.2 KiB
Python
"""
|
|
Django views for interacting with Build objects
|
|
"""
|
|
|
|
# -*- coding: utf-8 -*-
|
|
from __future__ import unicode_literals
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.views.generic import DetailView, ListView
|
|
|
|
from .models import Build
|
|
|
|
from InvenTree.views import AjaxDeleteView
|
|
from InvenTree.views import InvenTreeRoleMixin
|
|
from InvenTree.status_codes import BuildStatus
|
|
|
|
|
|
class BuildIndex(InvenTreeRoleMixin, ListView):
|
|
"""
|
|
View for displaying list of Builds
|
|
"""
|
|
model = Build
|
|
template_name = 'build/index.html'
|
|
context_object_name = 'builds'
|
|
|
|
def get_queryset(self):
|
|
""" Return all Build objects (order by date, newest first) """
|
|
return Build.objects.order_by('status', '-completion_date')
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(BuildIndex, self).get_context_data(**kwargs).copy()
|
|
|
|
context['BuildStatus'] = BuildStatus
|
|
|
|
context['active'] = self.get_queryset().filter(status__in=BuildStatus.ACTIVE_CODES)
|
|
|
|
context['completed'] = self.get_queryset().filter(status=BuildStatus.COMPLETE)
|
|
context['cancelled'] = self.get_queryset().filter(status=BuildStatus.CANCELLED)
|
|
|
|
return context
|
|
|
|
|
|
class BuildDetail(InvenTreeRoleMixin, DetailView):
|
|
"""
|
|
Detail view of a single Build object.
|
|
"""
|
|
|
|
model = Build
|
|
template_name = 'build/detail.html'
|
|
context_object_name = 'build'
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
ctx = super(DetailView, self).get_context_data(**kwargs)
|
|
|
|
build = self.get_object()
|
|
|
|
ctx['bom_price'] = build.part.get_price_info(build.quantity, buy=False)
|
|
ctx['BuildStatus'] = BuildStatus
|
|
ctx['sub_build_count'] = build.sub_build_count()
|
|
|
|
part = build.part
|
|
bom_items = build.bom_items
|
|
|
|
ctx['part'] = part
|
|
ctx['bom_items'] = bom_items
|
|
ctx['has_tracked_bom_items'] = build.has_tracked_bom_items()
|
|
ctx['has_untracked_bom_items'] = build.has_untracked_bom_items()
|
|
|
|
return ctx
|
|
|
|
|
|
class BuildDelete(AjaxDeleteView):
|
|
"""
|
|
View to delete a build
|
|
"""
|
|
|
|
model = Build
|
|
ajax_template_name = 'build/delete_build.html'
|
|
ajax_form_title = _('Delete Build Order')
|