2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-20 13:56:30 +00:00

More fixes

- Add a set of template tags for rendering status codes
- Improve build API filtering
- Remove some outdated files
- Fix unit testing
This commit is contained in:
Oliver Walters
2020-04-12 00:10:33 +10:00
parent 59778130cd
commit 7503596ea4
17 changed files with 94 additions and 116 deletions

View File

@ -1,5 +1,6 @@
{% extends "part/part_base.html" %}
{% block details %}
{% load status_codes %}
{% include "part/tabs.html" with tab="allocation" %}
@ -17,7 +18,7 @@
<td><a href="{% url 'build-detail' allocation.build.id %}">{{ allocation.build.title }}</a></td>
<td>{{ allocation.build.quantity }} &times <a href="{% url 'part-detail' allocation.build.part.id %}">{{ allocation.build.part.full_name }}</a></td>
<td>{{ allocation.quantity }}</td>
<td>{% include "build_status.html" with build=allocation.build %}</td>
<td>{% build_status allocation.build.status %}</td>
</tr>
{% endfor %}
</table>

View File

@ -7,9 +7,14 @@
<h3>Part Builds</h3>
<div id='button-toolbar'>
{% if part.active %}
<button class="btn btn-success" id='start-build'>Start New Build</button>
{% endif %}
<div class='button-toolbar container-flui' style='float: right';>
{% if part.active %}
<button class="btn btn-success" id='start-build'>Start New Build</button>
{% endif %}
<div class='filter-list' id='filter-list-build'>
<!-- Empty div for filters -->
</div>
</div>
</div>
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='build-table'>
@ -31,64 +36,12 @@
});
});
$("#build-table").inventreeTable({
queryParams: function(p) {
return {
part: {{ part.id }},
}
},
columns: [
{
field: 'pk',
title: 'ID',
visible: false,
},
{
field: 'title',
title: 'Title',
formatter: function(value, row, index, field) {
return renderLink(value, row.url);
}
},
{
field: 'quantity',
title: 'Quantity',
},
{
field: 'status',
title: 'Status',
formatter: function(value, row, index, field) {
var color = '';
switch (value) {
case 10: // Pending
color = 'label-info';
break;
case 20: // Allocated
color = 'label-primary';
break;
case 30: // Cancelled
color = 'label-danger';
break;
case 40: // Complete
color = 'label-success';
break;
default:
break;
}
var html = "<span class='label " + color + " label-large'>" + row.status_text + "</span>";
return html;
}
},
{
field: 'completion_date',
title: 'Completed'
}
],
url: "{% url 'api-build-list' %}",
loadBuildTable($("#build-table"), {
url: "{% url 'api-build-list' %}",
params: {
part_detail: "true",
part: {{ part.id }},
}
});
{% endblock %}

View File

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

View File

@ -7,25 +7,10 @@ from InvenTree import version
from InvenTree.helpers import decimal2string
from common.models import InvenTreeSetting
from InvenTree.status_codes import OrderStatus, StockStatus, BuildStatus
register = template.Library()
@register.simple_tag(takes_context=True)
def load_status_codes(context):
"""
Make the various StatusCodes available to the page context
"""
context['order_status_codes'] = OrderStatus.list()
context['stock_status_codes'] = StockStatus.list()
context['build_status_codes'] = BuildStatus.list()
# Need to return something as the result is rendered to the page
return ''
@register.simple_tag()
def decimal(x, *args, **kwargs):
""" Simplified rendering of a decimal number """

View File

@ -0,0 +1,38 @@
"""
Provide templates for the various model status codes.
"""
from django import template
from django.utils.safestring import mark_safe
from InvenTree.status_codes import OrderStatus, StockStatus, BuildStatus
register = template.Library()
@register.simple_tag
def order_status(key, *args, **kwargs):
return mark_safe(OrderStatus.render(key))
@register.simple_tag
def stock_status(key, *args, **kwargs):
return mark_safe(StockStatus.render(key))
@register.simple_tag
def build_status(key, *args, **kwargs):
return mark_safe(BuildStatus.render(key))
@register.simple_tag(takes_context=True)
def load_status_codes(context):
"""
Make the various StatusCodes available to the page context
"""
context['order_status_codes'] = OrderStatus.list()
context['stock_status_codes'] = StockStatus.list()
context['build_status_codes'] = BuildStatus.list()
# Need to return something as the result is rendered to the page
return ''

View File

@ -82,7 +82,8 @@ class PartAPITest(APITestCase):
def test_get_all_parts(self):
url = reverse('api-part-list')
response = self.client.get(url, format='json')
data = {'cascade': True}
response = self.client.get(url, data, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data), 8)