diff --git a/InvenTree/InvenTree/status_codes.py b/InvenTree/InvenTree/status_codes.py
index 3c68dceb75..44c71ea9ee 100644
--- a/InvenTree/InvenTree/status_codes.py
+++ b/InvenTree/InvenTree/status_codes.py
@@ -9,6 +9,26 @@ class StatusCode:
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 "{value}".format(label=label, value=value)
+ else:
+ return value
+
@classmethod
def list(cls):
"""
diff --git a/InvenTree/build/api.py b/InvenTree/build/api.py
index 1476af3dcd..5c059efaf8 100644
--- a/InvenTree/build/api.py
+++ b/InvenTree/build/api.py
@@ -38,7 +38,6 @@ class BuildList(generics.ListCreateAPIView):
]
filter_fields = [
- 'part',
]
def get_queryset(self):
@@ -49,6 +48,12 @@ class BuildList(generics.ListCreateAPIView):
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?
status = self.request.query_params.get('status', None)
diff --git a/InvenTree/build/templates/build/build_base.html b/InvenTree/build/templates/build/build_base.html
index d1842cd384..cd9ae463c2 100644
--- a/InvenTree/build/templates/build/build_base.html
+++ b/InvenTree/build/templates/build/build_base.html
@@ -1,6 +1,8 @@
{% extends "base.html" %}
{% load static %}
+{% load i18n %}
+{% load status_codes %}
{% block page_title %}
InvenTree | Build - {{ build }}
@@ -23,7 +25,6 @@ InvenTree | Build - {{ build }}
Build Details
-
@@ -50,7 +51,7 @@ InvenTree | Build - {{ build }}
{{ build.title }} |
- {% include "build_status.html" with build=build %} |
+ {% build_status build.status %} |
Part |
diff --git a/InvenTree/build/templates/build/detail.html b/InvenTree/build/templates/build/detail.html
index 8b8a53023b..42f8852ef9 100644
--- a/InvenTree/build/templates/build/detail.html
+++ b/InvenTree/build/templates/build/detail.html
@@ -2,6 +2,7 @@
{% load static %}
{% load i18n %}
{% block details %}
+{% load status_codes %}
{% include "build/tabs.html" with tab='details' %}
@@ -39,7 +40,7 @@
|
{% trans "Status" %} |
- {% include "build_status.html" with build=build %} |
+ {% build_status build.status %} |
{% if build.batch %}
diff --git a/InvenTree/build/tests.py b/InvenTree/build/tests.py
index 06eafa41ab..acd614425a 100644
--- a/InvenTree/build/tests.py
+++ b/InvenTree/build/tests.py
@@ -143,9 +143,7 @@ class TestBuildViews(TestCase):
content = str(response.content)
- # Content should contain build titles
- for build in Build.objects.all():
- self.assertIn(build.title, content)
+ self.assertIn("Part Builds", content)
def test_build_detail(self):
""" Test the detail view for a Build object """
diff --git a/InvenTree/company/templates/company/po_list.html b/InvenTree/company/templates/company/po_list.html
deleted file mode 100644
index 8b4204996f..0000000000
--- a/InvenTree/company/templates/company/po_list.html
+++ /dev/null
@@ -1,7 +0,0 @@
-{% for order in orders %}
-
- {{ order }} |
- {{ order.description }} |
- {% include "order/order_status.html" with order=order %} |
-
-{% endfor %}
\ No newline at end of file
diff --git a/InvenTree/order/templates/order/order_base.html b/InvenTree/order/templates/order/order_base.html
index e5ed77cf4f..420f312310 100644
--- a/InvenTree/order/templates/order/order_base.html
+++ b/InvenTree/order/templates/order/order_base.html
@@ -3,6 +3,7 @@
{% load i18n %}
{% load static %}
{% load inventree_extras %}
+{% load status_codes %}
{% block page_title %}
InvenTree | {{ order }}
@@ -69,7 +70,7 @@ InvenTree | {{ order }}
|
{% trans "Status" %} |
- {% include "order/order_status.html" %} |
+ {% order_status order.status %} |
{% if order.link %}
diff --git a/InvenTree/order/templates/order/purchase_order_detail.html b/InvenTree/order/templates/order/purchase_order_detail.html
index d2930cb8d1..8196ada70d 100644
--- a/InvenTree/order/templates/order/purchase_order_detail.html
+++ b/InvenTree/order/templates/order/purchase_order_detail.html
@@ -1,6 +1,7 @@
{% extends "order/order_base.html" %}
{% load inventree_extras %}
+{% load status_codes %}
{% load i18n %}
{% load static %}
diff --git a/InvenTree/part/templates/part/allocation.html b/InvenTree/part/templates/part/allocation.html
index 913469997f..cab6c44022 100644
--- a/InvenTree/part/templates/part/allocation.html
+++ b/InvenTree/part/templates/part/allocation.html
@@ -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 @@
{{ allocation.build.title }} |
{{ allocation.build.quantity }} × {{ allocation.build.part.full_name }} |
{{ allocation.quantity }} |
- {% include "build_status.html" with build=allocation.build %} |
+ {% build_status allocation.build.status %} |
{% endfor %}
diff --git a/InvenTree/part/templates/part/build.html b/InvenTree/part/templates/part/build.html
index b532ff73bf..442693ddeb 100644
--- a/InvenTree/part/templates/part/build.html
+++ b/InvenTree/part/templates/part/build.html
@@ -7,9 +7,14 @@
Part Builds
@@ -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 = "" + row.status_text + "";
-
- 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 %}
\ No newline at end of file
diff --git a/InvenTree/part/templates/part/build_list.html b/InvenTree/part/templates/part/build_list.html
deleted file mode 100644
index 282997c147..0000000000
--- a/InvenTree/part/templates/part/build_list.html
+++ /dev/null
@@ -1,10 +0,0 @@
-{% for build in builds %}
-
- {{ build.title }} |
- {{ build.quantity }} |
-
- {% include "build_status.html" with build=build %}
- |
- {% if build.completion_date %}{{ build.completion_date }}{% endif %} |
-
-{% endfor %}
\ No newline at end of file
diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py
index 3e71262dec..e68e9c23dc 100644
--- a/InvenTree/part/templatetags/inventree_extras.py
+++ b/InvenTree/part/templatetags/inventree_extras.py
@@ -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 """
diff --git a/InvenTree/part/templatetags/status_codes.py b/InvenTree/part/templatetags/status_codes.py
new file mode 100644
index 0000000000..18f84032ce
--- /dev/null
+++ b/InvenTree/part/templatetags/status_codes.py
@@ -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 ''
diff --git a/InvenTree/part/test_api.py b/InvenTree/part/test_api.py
index 64ae616720..ca3c747b12 100644
--- a/InvenTree/part/test_api.py
+++ b/InvenTree/part/test_api.py
@@ -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)
diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html
index 6c38335b3e..46e26b6ff1 100644
--- a/InvenTree/stock/templates/stock/item_base.html
+++ b/InvenTree/stock/templates/stock/item_base.html
@@ -1,6 +1,7 @@
{% extends "stock/stock_app_base.html" %}
{% load static %}
{% load inventree_extras %}
+{% load status_codes %}
{% load i18n %}
{% block content %}
@@ -172,7 +173,7 @@
|
{% trans "Status" %} |
- {{ item.get_status_display }} |
+ {% stock_status item.status %} |
diff --git a/InvenTree/templates/build_status.html b/InvenTree/templates/build_status.html
deleted file mode 100644
index b18b81e16f..0000000000
--- a/InvenTree/templates/build_status.html
+++ /dev/null
@@ -1,11 +0,0 @@
-{% if build.status == BuildStatus.PENDING %}
-
-{% elif build.status == BuildStatus.ALLOCATED %}
-
-{% elif build.status == BuildStatus.CANCELLED %}
-
-{% elif build.status == BuildStatus.COMPLETE %}
-
-{% endif %}
-{{ build.get_status_display }}
-
\ No newline at end of file
diff --git a/InvenTree/templates/table_filters.html b/InvenTree/templates/table_filters.html
index 0bff04a7aa..e3dd78be19 100644
--- a/InvenTree/templates/table_filters.html
+++ b/InvenTree/templates/table_filters.html
@@ -1,5 +1,5 @@
{% load i18n %}
-{% load inventree_extras %}
+{% load status_codes %}
{% load_status_codes %}