Display list of build outputs in the Build tab

- Allow StockList api to be filtered by Build id
This commit is contained in:
Oliver Walters 2020-02-17 23:31:23 +11:00
parent e483b42df6
commit 23aebab6d0
6 changed files with 53 additions and 2 deletions

View File

@ -97,6 +97,10 @@ class Build(models.Model):
notes = MarkdownxField(blank=True, help_text=_('Extra build notes'))
@property
def output_count(self):
return self.build_outputs.count()
@transaction.atomic
def cancelBuild(self, user):
""" Mark the Build as CANCELLED
@ -235,7 +239,7 @@ class Build(models.Model):
now=str(datetime.now().date())
)
if self.part.trackable:
if self.part.trackable and serial_numbers:
# Add new serial numbers
for serial in serial_numbers:
item = StockItem.objects.create(

View File

@ -90,6 +90,10 @@ InvenTree | Build - {{ build }}
{% endblock %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/inventree/stock.js' %}"></script>
{% endblock %}
{% block js_ready %}
$("#build-edit").click(function () {

View File

@ -0,0 +1,32 @@
{% extends "build/build_base.html" %}
{% load static %}
{% load i18n %}
{% block details %}
{% include "build/tabs.html" with tab='output' %}
<h4>{% trans "Build Outputs" %}</h4>
<hr>
{% include "stock_table.html" %}
{% endblock %}
{% block js_ready %}
{{ block.super }}
loadStockTable($("#stock-table"), {
params: {
location_detail: true,
part_details: true,
build: {{ build.id }},
},
groupByField: 'location',
buttons: [
'#stock-options',
],
url: "{% url 'api-stock-list' %}",
});
{% endblock %}

View File

@ -4,6 +4,9 @@
<li{% if tab == 'details' %} class='active'{% endif %}>
<a href="{% url 'build-detail' build.id %}">{% trans "Details" %}</a>
</li>
<li{% if tab == 'output' %} class='active'{% endif %}>
<a href="{% url 'build-output' build.id %}">{% trans "Outputs" %}{% if build.output_count > 0%}<span class='badge'>{{ build.output_count }}</span>{% endif %}</a>
</li>
<li{% if tab == 'notes' %} class='active'{% endif %}>
<a href="{% url 'build-notes' build.id %}">{% trans "Notes" %}{% if build.notes %} <span class='glyphicon glyphicon-small glyphicon-info-sign'></span>{% endif %}</a>
</li>

View File

@ -26,6 +26,9 @@ build_detail_urls = [
url(r'^unallocate/', views.BuildUnallocate.as_view(), name='build-unallocate'),
url(r'^notes/', views.BuildNotes.as_view(), name='build-notes'),
url(r'^output/', views.BuildDetail.as_view(template_name='build/build_output.html'), name='build-output'),
url(r'^.*$', views.BuildDetail.as_view(), name='build-detail'),
]

View File

@ -260,6 +260,8 @@ class StockList(generics.ListCreateAPIView):
- ancestor: Filter by an 'ancestor' StockItem
"""
queryset = StockItem.objects.all()
def get_serializer(self, *args, **kwargs):
try:
@ -334,7 +336,9 @@ class StockList(generics.ListCreateAPIView):
"""
# Start with all objects
stock_list = StockItem.objects.filter(customer=None, belongs_to=None)
stock_list = super(StockList, self).get_queryset()
stock_list = stock_list.filter(customer=None, belongs_to=None)
# Does the client wish to filter by the Part ID?
part_id = self.request.query_params.get('part', None)
@ -426,6 +430,7 @@ class StockList(generics.ListCreateAPIView):
'supplier_part',
'customer',
'belongs_to',
'build',
# 'status' TODO - There are some issues filtering based on an enumeration field
]