From a9fffe6a734dfcba897b28023e77f18bba706e95 Mon Sep 17 00:00:00 2001 From: eeintech Date: Wed, 16 Sep 2020 17:02:24 -0500 Subject: [PATCH] Added latest parts and invalid BOMs on homepage --- InvenTree/part/api.py | 21 +++++++++ .../templates/InvenTree/bom_invalid.html | 15 +++++++ InvenTree/templates/InvenTree/index.html | 44 ++++++++++++++++++- .../templates/InvenTree/latest_parts.html | 15 +++++++ .../templates/InvenTree/starred_parts.html | 2 +- InvenTree/templates/collapse_index.html | 19 ++++++++ 6 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 InvenTree/templates/InvenTree/bom_invalid.html create mode 100644 InvenTree/templates/InvenTree/latest_parts.html create mode 100644 InvenTree/templates/collapse_index.html diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index abc4181895..0afd79af55 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -405,6 +405,27 @@ class PartList(generics.ListCreateAPIView): except (ValueError, Part.DoesNotExist): pass + # Filter by latest part creation date + latest_parts = params.get('latest_parts', None) + + if latest_parts is not None: + # Get the last 5 created parts + queryset = queryset.order_by('-creation_date')[:5] + + # Filter invalid BOMs + bom_invalid = params.get('bom_invalid', None) + + if bom_invalid is not None: + # Get assemblies with invalid BOMs + assemblies = queryset.filter(active=True).filter(assembly=True) + valid_boms = [] + + for part in assemblies: + if part.is_bom_valid: + valid_boms.append(part.pk) + + queryset = assemblies.exclude(pk__in=valid_boms) + # Filter by 'starred' parts? starred = params.get('starred', None) diff --git a/InvenTree/templates/InvenTree/bom_invalid.html b/InvenTree/templates/InvenTree/bom_invalid.html new file mode 100644 index 0000000000..a0cf6ed6d1 --- /dev/null +++ b/InvenTree/templates/InvenTree/bom_invalid.html @@ -0,0 +1,15 @@ +{% extends "collapse_index.html" %} + +{% load i18n %} + +{% block collapse_title %} + +{% trans "BOM - Missing Validation" %}0 +{% endblock %} + +{% block collapse_content %} + + +
+ +{% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/InvenTree/index.html b/InvenTree/templates/InvenTree/index.html index 570378e55d..e8d46e6f85 100644 --- a/InvenTree/templates/InvenTree/index.html +++ b/InvenTree/templates/InvenTree/index.html @@ -7,9 +7,24 @@ InvenTree | Index {% block content %}

InvenTree


-{% include "InvenTree/starred_parts.html" with collapse_id="starred" %} -{% include "InvenTree/low_stock.html" with collapse_id="order" %} +
+
+ {% include "InvenTree/latest_parts.html" with collapse_id="latest" %} +
+
+ {% include "InvenTree/bom_invalid.html" with collapse_id="bom_invalid" %} +
+
+ +
+
+ {% include "InvenTree/starred_parts.html" with collapse_id="starred" %} +
+
+ {% include "InvenTree/low_stock.html" with collapse_id="order" %} +
+
{% endblock %} @@ -21,6 +36,18 @@ InvenTree | Index {{ block.super }} +loadPartTable("#latest-parts-table", "{% url 'api-part-list' %}", { + params: { + "latest_parts": true, + } +}); + +loadPartTable("#bom-invalid-table", "{% url 'api-part-list' %}", { + params: { + "bom_invalid": true, + } +}); + loadPartTable("#starred-parts-table", "{% url 'api-part-list' %}", { params: { "starred": true, @@ -33,6 +60,19 @@ loadPartTable("#low-stock-table", "{% url 'api-part-list' %}", { } }); +$("#bom-invalid-table").on('load-success.bs.table', function() { + var count = $("#bom-invalid-table").bootstrapTable('getData').length; + + $("#bom-invalid-count").html(count); +}); + + +$("#latest-parts-table").on('load-success.bs.table', function() { + var count = $("#latest-parts-table").bootstrapTable('getData').length; + + $("#latest-parts-count").html(count); +}); + $("#starred-parts-table").on('load-success.bs.table', function() { var count = $("#starred-parts-table").bootstrapTable('getData').length; diff --git a/InvenTree/templates/InvenTree/latest_parts.html b/InvenTree/templates/InvenTree/latest_parts.html new file mode 100644 index 0000000000..e9c9879740 --- /dev/null +++ b/InvenTree/templates/InvenTree/latest_parts.html @@ -0,0 +1,15 @@ +{% extends "collapse_index.html" %} + +{% load i18n %} + +{% block collapse_title %} + +{% trans "Latest Parts" %}0 +{% endblock %} + +{% block collapse_content %} + + +
+ +{% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/InvenTree/starred_parts.html b/InvenTree/templates/InvenTree/starred_parts.html index f13987e3c5..f852bf0f83 100644 --- a/InvenTree/templates/InvenTree/starred_parts.html +++ b/InvenTree/templates/InvenTree/starred_parts.html @@ -9,7 +9,7 @@ {% block collapse_content %} - +
{% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/collapse_index.html b/InvenTree/templates/collapse_index.html new file mode 100644 index 0000000000..d87f63b244 --- /dev/null +++ b/InvenTree/templates/collapse_index.html @@ -0,0 +1,19 @@ +{% block collapse_preamble %} +{% endblock %} +
+
+
+ + {% block collapse_heading %} + {% endblock %} +
+
+
+ {% block collapse_content %} + {% endblock %} +
+
+
+
\ No newline at end of file