mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +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:
parent
59778130cd
commit
7503596ea4
@ -9,6 +9,26 @@ class StatusCode:
|
|||||||
|
|
||||||
labels = {}
|
labels = {}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def render(cls, key):
|
||||||
|
"""
|
||||||
|
Render the value as a label.
|
||||||
|
"""
|
||||||
|
|
||||||
|
print("Rendering:", key, cls.options)
|
||||||
|
|
||||||
|
# If the key cannot be found, pass it back
|
||||||
|
if key not in cls.options.keys():
|
||||||
|
return key
|
||||||
|
|
||||||
|
value = cls.options.get(key, key)
|
||||||
|
label = cls.labels.get(key, None)
|
||||||
|
|
||||||
|
if label:
|
||||||
|
return "<span class='label label-{label}'>{value}</span>".format(label=label, value=value)
|
||||||
|
else:
|
||||||
|
return value
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def list(cls):
|
def list(cls):
|
||||||
"""
|
"""
|
||||||
|
@ -38,7 +38,6 @@ class BuildList(generics.ListCreateAPIView):
|
|||||||
]
|
]
|
||||||
|
|
||||||
filter_fields = [
|
filter_fields = [
|
||||||
'part',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
@ -49,6 +48,12 @@ class BuildList(generics.ListCreateAPIView):
|
|||||||
|
|
||||||
build_list = super().get_queryset()
|
build_list = super().get_queryset()
|
||||||
|
|
||||||
|
# Filter by part
|
||||||
|
part = self.request.query_params.get('part', None)
|
||||||
|
|
||||||
|
if part is not None:
|
||||||
|
build_list = build_list.filter(part=part)
|
||||||
|
|
||||||
# Filter by build status?
|
# Filter by build status?
|
||||||
status = self.request.query_params.get('status', None)
|
status = self.request.query_params.get('status', None)
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% load status_codes %}
|
||||||
|
|
||||||
{% block page_title %}
|
{% block page_title %}
|
||||||
InvenTree | Build - {{ build }}
|
InvenTree | Build - {{ build }}
|
||||||
@ -23,7 +25,6 @@ InvenTree | Build - {{ build }}
|
|||||||
</div>
|
</div>
|
||||||
<div class='media-body'>
|
<div class='media-body'>
|
||||||
<h4>Build Details</h4>
|
<h4>Build Details</h4>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<div class='btn-row'>
|
<div class='btn-row'>
|
||||||
<div class='btn-group'>
|
<div class='btn-group'>
|
||||||
@ -50,7 +51,7 @@ InvenTree | Build - {{ build }}
|
|||||||
<table class='table table-striped table-condensed'>
|
<table class='table table-striped table-condensed'>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ build.title }}</td>
|
<td>{{ build.title }}</td>
|
||||||
<td>{% include "build_status.html" with build=build %}</td>
|
<td>{% build_status build.status %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Part</td>
|
<td>Part</td>
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% block details %}
|
{% block details %}
|
||||||
|
{% load status_codes %}
|
||||||
|
|
||||||
{% include "build/tabs.html" with tab='details' %}
|
{% include "build/tabs.html" with tab='details' %}
|
||||||
|
|
||||||
@ -39,7 +40,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><span class='fas fa-info'></span></td>
|
<td><span class='fas fa-info'></span></td>
|
||||||
<td>{% trans "Status" %}</td>
|
<td>{% trans "Status" %}</td>
|
||||||
<td>{% include "build_status.html" with build=build %}</td>
|
<td>{% build_status build.status %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% if build.batch %}
|
{% if build.batch %}
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -143,9 +143,7 @@ class TestBuildViews(TestCase):
|
|||||||
|
|
||||||
content = str(response.content)
|
content = str(response.content)
|
||||||
|
|
||||||
# Content should contain build titles
|
self.assertIn("Part Builds", content)
|
||||||
for build in Build.objects.all():
|
|
||||||
self.assertIn(build.title, content)
|
|
||||||
|
|
||||||
def test_build_detail(self):
|
def test_build_detail(self):
|
||||||
""" Test the detail view for a Build object """
|
""" Test the detail view for a Build object """
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
{% for order in orders %}
|
|
||||||
<tr>
|
|
||||||
<td>{{ order }}</td>
|
|
||||||
<td>{{ order.description }}</td>
|
|
||||||
<td>{% include "order/order_status.html" with order=order %}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
@ -3,6 +3,7 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
{% load inventree_extras %}
|
{% load inventree_extras %}
|
||||||
|
{% load status_codes %}
|
||||||
|
|
||||||
{% block page_title %}
|
{% block page_title %}
|
||||||
InvenTree | {{ order }}
|
InvenTree | {{ order }}
|
||||||
@ -69,7 +70,7 @@ InvenTree | {{ order }}
|
|||||||
<tr>
|
<tr>
|
||||||
<td><span class='fas fa-info'></span></td>
|
<td><span class='fas fa-info'></span></td>
|
||||||
<td>{% trans "Status" %}</td>
|
<td>{% trans "Status" %}</td>
|
||||||
<td>{% include "order/order_status.html" %}</td>
|
<td>{% order_status order.status %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% if order.link %}
|
{% if order.link %}
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{% extends "order/order_base.html" %}
|
{% extends "order/order_base.html" %}
|
||||||
|
|
||||||
{% load inventree_extras %}
|
{% load inventree_extras %}
|
||||||
|
{% load status_codes %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{% extends "part/part_base.html" %}
|
{% extends "part/part_base.html" %}
|
||||||
{% block details %}
|
{% block details %}
|
||||||
|
{% load status_codes %}
|
||||||
|
|
||||||
{% include "part/tabs.html" with tab="allocation" %}
|
{% 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><a href="{% url 'build-detail' allocation.build.id %}">{{ allocation.build.title }}</a></td>
|
||||||
<td>{{ allocation.build.quantity }} × <a href="{% url 'part-detail' allocation.build.part.id %}">{{ allocation.build.part.full_name }}</a></td>
|
<td>{{ allocation.build.quantity }} × <a href="{% url 'part-detail' allocation.build.part.id %}">{{ allocation.build.part.full_name }}</a></td>
|
||||||
<td>{{ allocation.quantity }}</td>
|
<td>{{ allocation.quantity }}</td>
|
||||||
<td>{% include "build_status.html" with build=allocation.build %}</td>
|
<td>{% build_status allocation.build.status %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
@ -7,9 +7,14 @@
|
|||||||
<h3>Part Builds</h3>
|
<h3>Part Builds</h3>
|
||||||
|
|
||||||
<div id='button-toolbar'>
|
<div id='button-toolbar'>
|
||||||
|
<div class='button-toolbar container-flui' style='float: right';>
|
||||||
{% if part.active %}
|
{% if part.active %}
|
||||||
<button class="btn btn-success" id='start-build'>Start New Build</button>
|
<button class="btn btn-success" id='start-build'>Start New Build</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<div class='filter-list' id='filter-list-build'>
|
||||||
|
<!-- Empty div for filters -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='build-table'>
|
<table class='table table-striped table-condensed' data-toolbar='#button-toolbar' id='build-table'>
|
||||||
@ -31,64 +36,12 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#build-table").inventreeTable({
|
loadBuildTable($("#build-table"), {
|
||||||
queryParams: function(p) {
|
url: "{% url 'api-build-list' %}",
|
||||||
return {
|
params: {
|
||||||
|
part_detail: "true",
|
||||||
part: {{ part.id }},
|
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' %}",
|
|
||||||
});
|
});
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -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 %}
|
|
@ -7,25 +7,10 @@ from InvenTree import version
|
|||||||
from InvenTree.helpers import decimal2string
|
from InvenTree.helpers import decimal2string
|
||||||
|
|
||||||
from common.models import InvenTreeSetting
|
from common.models import InvenTreeSetting
|
||||||
from InvenTree.status_codes import OrderStatus, StockStatus, BuildStatus
|
|
||||||
|
|
||||||
register = template.Library()
|
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()
|
@register.simple_tag()
|
||||||
def decimal(x, *args, **kwargs):
|
def decimal(x, *args, **kwargs):
|
||||||
""" Simplified rendering of a decimal number """
|
""" Simplified rendering of a decimal number """
|
||||||
|
38
InvenTree/part/templatetags/status_codes.py
Normal file
38
InvenTree/part/templatetags/status_codes.py
Normal 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 ''
|
@ -82,7 +82,8 @@ class PartAPITest(APITestCase):
|
|||||||
|
|
||||||
def test_get_all_parts(self):
|
def test_get_all_parts(self):
|
||||||
url = reverse('api-part-list')
|
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(response.status_code, status.HTTP_200_OK)
|
||||||
self.assertEqual(len(response.data), 8)
|
self.assertEqual(len(response.data), 8)
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{% extends "stock/stock_app_base.html" %}
|
{% extends "stock/stock_app_base.html" %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
{% load inventree_extras %}
|
{% load inventree_extras %}
|
||||||
|
{% load status_codes %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
@ -172,7 +173,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><span class='fas fa-info'></span></td>
|
<td><span class='fas fa-info'></span></td>
|
||||||
<td>{% trans "Status" %}</td>
|
<td>{% trans "Status" %}</td>
|
||||||
<td>{{ item.get_status_display }}</td>
|
<td>{% stock_status item.status %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
{% if build.status == BuildStatus.PENDING %}
|
|
||||||
<span class='label label-large label-info'>
|
|
||||||
{% elif build.status == BuildStatus.ALLOCATED %}
|
|
||||||
<span class='label label-large label-primary'>
|
|
||||||
{% elif build.status == BuildStatus.CANCELLED %}
|
|
||||||
<span class='label label-large label-danger'>
|
|
||||||
{% elif build.status == BuildStatus.COMPLETE %}
|
|
||||||
<span class='label label-large label-success'>
|
|
||||||
{% endif %}
|
|
||||||
{{ build.get_status_display }}
|
|
||||||
</span>
|
|
@ -1,5 +1,5 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load inventree_extras %}
|
{% load status_codes %}
|
||||||
|
|
||||||
{% load_status_codes %}
|
{% load_status_codes %}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user