2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00

Added views and pages for Build model

- Edit / create
- View details
- View build index at /build/
This commit is contained in:
Oliver 2018-04-17 23:13:41 +10:00
parent 11b9fb10d8
commit 291992ab7f
16 changed files with 177 additions and 10 deletions

33
InvenTree/build/forms.py Normal file
View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
from .models import Build
class EditBuildForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(EditBuildForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_id = 'id-edit-part-form'
self.helper.form_class = 'blueForms'
self.helper.form_method = 'post'
self.helper.add_input(Submit('submit', 'Submit'))
class Meta:
model = Build
fields = [
'title',
'notes',
'part',
'batch',
'quantity',
'status',
'completion_date',
]

View File

@ -14,6 +14,9 @@ class Build(models.Model):
Parts are then taken from stock Parts are then taken from stock
""" """
def get_absolute_url(self):
return '/build/{pk}/'.format(pk=self.id)
# Build status codes # Build status codes
PENDING = 10 # Build is pending / active PENDING = 10 # Build is pending / active
HOLDING = 20 # Build is currently being held HOLDING = 20 # Build is currently being held

View File

@ -0,0 +1,9 @@
{% for build in builds %}
<tr>
<td><a href="{% url 'build-detail' build.id %}">{{ build.title }}</a></td>
<td><a href="{% url 'part-build' build.part.id %}">{{ build.part.name }}</a></td>
<td>{{ build.quantity }}</td>
<td>{% include "build_status.html" with build=build %}
</tr>
{% endfor %}

View File

@ -0,0 +1,5 @@
{% extends "create_edit_obj.html" %}
{% block obj_title %}
Create a new build
{% endblock %}

View File

@ -1,3 +1,41 @@
{% include "base.html" %} {% include "base.html" %}
Build detail for Build No. {{ build.id }}. {% block content %}
<h3>Build Details</h3>
<table class='table table-striped'>
<tr>
<td>Title</td><td>{{ build.title }}</td>
</tr>
<tr>
<td>Part</td><td><a href="{% url 'part-build' build.part.id %}">{{ build.part.name }}</a></td>
</tr>
<tr>
<td>Quantity</td><td>{{ build.quantity }}</td>
</tr>
{% if build.batch %}
<tr>
<td>Batch</td><td>{{ build.batch }}</td>
</tr>
{% endif %}
<tr>
<td>Status</td><td>{% include "build_status.html" with build=build %}</td>
</tr>
<tr>
<td>Created</td><td>{{ build.creation_date }}</td>
</tr>
{% if batch.completion_date %}
<tr>
<td>Completed</td><td>{{ build.creation_date }}</td>
</tr>
{% endif %}
{% if build.notes %}
<tr>
<td>Notes</td><td>{{ build.notes }}</td>
</tr>
{% endif %}
</table>
<div class='container-fluid'>
<a href="{% url 'build-edit' build.id %}"><button class="btn btn-info">Edit Build</button></a>
{% endblock %}

View File

@ -2,6 +2,33 @@
{% block content %} {% block content %}
<h3>Builds</h3> <h3>Part Builds</h3>
<table class='table table-striped'>
<tr>
<th></th>
<th>Part</th>
<th>Quantity</th>
<th>Status</th>
</tr>
{% if active|length > 0 %}
<tr><td colspan="4"><b>Active Builds</b></td></tr>
{% include "build/build_list.html" with builds=active %}
{% endif %}
{% if complete|length > 0 %}
<tr></tr>
<tr><td colspan="4"><b>Completed Builds</b></td></tr>
{% include "build/build_list.html" with builds=complete %}
{% endif %}
{% if cancelled|length > 0 %}
<tr></tr>
<tr><td colspan="4"><b>Cancelled Builds</b></td></tr>
{% include "build/build_list.html" with builds=cancelled.all %}
{% endif %}
</table>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,5 @@
{% extends "create_edit_obj.html" %}
{% block obj_title %}
Edit build details
{% endblock %}

View File

@ -4,12 +4,13 @@ from django.views.generic.base import RedirectView
from . import views from . import views
build_detail_urls = [ build_detail_urls = [
url(r'^edit/?', views.BuildUpdate.as_view(), name='build-edit'),
url(r'^.*$', views.BuildDetail.as_view(), name='build-detail'), url(r'^.*$', views.BuildDetail.as_view(), name='build-detail'),
] ]
build_urls = [ build_urls = [
# url(r'new/?', views.BuildCreate.as_view(), name='build-create'), url(r'new/?', views.BuildCreate.as_view(), name='build-create'),
url(r'^(?P<pk>\d+)/', include(build_detail_urls)), url(r'^(?P<pk>\d+)/', include(build_detail_urls)),

View File

@ -7,16 +7,56 @@ from django.http import HttpResponseRedirect
from django.views.generic import DetailView, ListView from django.views.generic import DetailView, ListView
from django.views.generic.edit import UpdateView, DeleteView, CreateView from django.views.generic.edit import UpdateView, DeleteView, CreateView
from part.models import Part
from .models import Build from .models import Build
from .forms import EditBuildForm
class BuildIndex(ListView): class BuildIndex(ListView):
model = Build model = Build
template_name = 'build/index.html' template_name = 'build/index.html'
context_object_name = 'builds' context_object_name = 'builds'
def get_queryset(self):
return Build.objects.order_by('status', '-completion_date')
def get_context_data(self, **kwargs):
context = super(BuildIndex, self).get_context_data(**kwargs).copy()
context['active'] = self.get_queryset().filter(status__in=[Build.PENDING, Build.HOLDING])
context['complete'] = self.get_queryset().filter(status=Build.COMPLETE)
context['cancelled'] = self.get_queryset().filter(status=Build.CANCELLED)
return context
class BuildDetail(DetailView): class BuildDetail(DetailView):
model = Build model = Build
template_name = 'build/detail.html' template_name = 'build/detail.html'
context_object_name = 'build' context_object_name = 'build'
class BuildCreate(CreateView):
model = Build
template_name = 'build/create.html'
context_object_name = 'build'
form_class = EditBuildForm
def get_initial(self):
initials = super(BuildCreate, self).get_initial().copy()
part_id = self.request.GET.get('part', None)
if part_id:
initials['part'] = get_object_or_404(Part, pk=part_id)
return initials
class BuildUpdate(UpdateView):
model = Build
form_class = EditBuildForm
context_object_name = 'build'
template_name = 'build/update.html'

View File

@ -6,9 +6,10 @@
<a class="navbar-brand" href="/"><img src="{% static 'img/inventree.png' %}" width="40" height="40"/></a> <a class="navbar-brand" href="/"><img src="{% static 'img/inventree.png' %}" width="40" height="40"/></a>
</div> </div>
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li><a href="/part/">Parts</a></li> <li><a href="{% url 'part-index' %}">Parts</a></li>
<li><a href="/stock/">Stock</a></li> <li><a href="{% url 'stock-index' %}">Stock</a></li>
<li><a href="/supplier/">Suppliers</a></li> <li><a href="{% url 'build-index' %}">Build</a></li>
<li><a href="{% url 'supplier-index' %}">Suppliers</a></li>
</ul> </ul>
</div> </div>
</nav> </nav>

View File

@ -20,7 +20,7 @@
<td><a href="{% url 'build-detail' build.id %}">{{ build.title }}</a></td> <td><a href="{% url 'build-detail' build.id %}">{{ build.title }}</a></td>
<td><a href="{% url 'part-detail' build.part.id %}">{{ build.part.name }}</a></td> <td><a href="{% url 'part-detail' build.part.id %}">{{ build.part.name }}</a></td>
<td>Quantity</td> <td>Quantity</td>
<td>{% include "part/build_status.html" with build=build %}</td> <td>{% include "build_status.html" with build=build %}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View File

@ -31,4 +31,7 @@
</table> </table>
<div class='container-fluid'>
<a href="{% url 'build-create' %}?part={{ part.id }}"><button class="btn btn-success">Start New Build</button></a>
{% endblock %} {% endblock %}

View File

@ -3,7 +3,7 @@
<td><a href="{% url 'build-detail' build.id %}">{{ build.title }}</a></td> <td><a href="{% url 'build-detail' build.id %}">{{ build.title }}</a></td>
<td>{{ build.quantity }}</td> <td>{{ build.quantity }}</td>
<td> <td>
{% include "part/build_status.html" with build=build %} {% include "build_status.html" with build=build %}
</td> </td>
<td>{% if build.completion_date %}{{ build.completion_date }}{% endif %}</td> <td>{% if build.completion_date %}{{ build.completion_date }}{% endif %}</td>
</tr> </tr>

View File

@ -77,7 +77,7 @@
{% if part.allocation_count > part.total_stock %} {% if part.allocation_count > part.total_stock %}
<td><span class='label label-danger'>{{ part.allocation_count }}</span> <td><span class='label label-danger'>{{ part.allocation_count }}</span>
{% else %} {% else %}
{{ part.allocation_count }} {{ part.total_stock }} {{ part.allocation_count }}
{% endif %} {% endif %}
</td> </td>
</tr> </tr>

View File

@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import forms from django import forms
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit from crispy_forms.layout import Submit
from .models import StockLocation, StockItem from .models import StockLocation, StockItem
class EditStockLocationForm(forms.ModelForm): class EditStockLocationForm(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):