From 3d597cc3c3b7769e4367aea479a3220d69f75776 Mon Sep 17 00:00:00 2001
From: eeintech <eeintech@eeinte.ch>
Date: Thu, 17 Sep 2020 14:36:05 -0500
Subject: [PATCH] Added 'Pending' builds report to homepage, includes builds
 with 'Allocated' status

---
 InvenTree/build/api.py                        |  5 +++-
 .../templates/InvenTree/bom_invalid.html      |  2 +-
 .../templates/InvenTree/build_pending.html    | 15 ++++++++++++
 InvenTree/templates/InvenTree/index.html      | 24 ++++++++++++++++++-
 InvenTree/templates/InvenTree/low_stock.html  |  2 +-
 .../templates/InvenTree/starred_parts.html    |  2 +-
 InvenTree/templates/js/build.html             |  2 +-
 7 files changed, 46 insertions(+), 6 deletions(-)
 create mode 100644 InvenTree/templates/InvenTree/build_pending.html

diff --git a/InvenTree/build/api.py b/InvenTree/build/api.py
index 22514ee7b7..592ff5dc16 100644
--- a/InvenTree/build/api.py
+++ b/InvenTree/build/api.py
@@ -59,7 +59,10 @@ class BuildList(generics.ListCreateAPIView):
         status = self.request.query_params.get('status', None)
 
         if status is not None:
-            queryset = queryset.filter(status=status)
+            # Get status codes
+            codes = status.split('-')
+            # Filter by codes
+            queryset = queryset.filter(status__in=codes)
 
         # Filter by associated part?
         part = self.request.query_params.get('part', None)
diff --git a/InvenTree/templates/InvenTree/bom_invalid.html b/InvenTree/templates/InvenTree/bom_invalid.html
index a0cf6ed6d1..84f4fd7938 100644
--- a/InvenTree/templates/InvenTree/bom_invalid.html
+++ b/InvenTree/templates/InvenTree/bom_invalid.html
@@ -4,7 +4,7 @@
 
 {% block collapse_title %}
 <span class='fas fa-times-circle icon-header'></span>
-{% trans "BOM - Missing Validation" %}<span class='badge' id='bom-invalid-count'>0</span>
+{% trans "BOM Waiting Validation" %}<span class='badge' id='bom-invalid-count'>0</span>
 {% endblock %}
 
 {% block collapse_content %}
diff --git a/InvenTree/templates/InvenTree/build_pending.html b/InvenTree/templates/InvenTree/build_pending.html
new file mode 100644
index 0000000000..8d8ba7befa
--- /dev/null
+++ b/InvenTree/templates/InvenTree/build_pending.html
@@ -0,0 +1,15 @@
+{% extends "collapse_index.html" %}
+
+{% load i18n %}
+
+{% block collapse_title %}
+<span class='fas fa-times-circle icon-header'></span>
+{% trans "Pending Builds" %}<span class='badge' id='build-pending-count'>0</span>
+{% endblock %}
+
+{% block collapse_content %}
+
+<table class='table table-striped table-condensed' id='build-pending-table'>
+</table>
+
+{% endblock %}
\ No newline at end of file
diff --git a/InvenTree/templates/InvenTree/index.html b/InvenTree/templates/InvenTree/index.html
index e8d46e6f85..b754414efc 100644
--- a/InvenTree/templates/InvenTree/index.html
+++ b/InvenTree/templates/InvenTree/index.html
@@ -10,7 +10,7 @@ InvenTree | Index
 
 <div class="row">
     <div class="col-sm-6">
-        {% include "InvenTree/latest_parts.html" with collapse_id="latest" %}
+        {% include "InvenTree/latest_parts.html" with collapse_id="latest_parts" %}
     </div>
     <div class="col-sm-6">
         {% include "InvenTree/bom_invalid.html" with collapse_id="bom_invalid" %}
@@ -26,6 +26,14 @@ InvenTree | Index
     </div>
 </div>
 
+<div class="row">
+    <div class="col-sm-6">
+        {% include "InvenTree/build_pending.html" with collapse_id="build_pending" %}
+    </div>
+    <div class="col-sm-6">
+    </div>
+</div>
+
 {% endblock %}
 
 {% block js_load %}
@@ -60,6 +68,14 @@ loadPartTable("#low-stock-table", "{% url 'api-part-list' %}", {
     }
 });
 
+loadBuildTable("#build-pending-table", {
+    url: "{% url 'api-build-list' %}",
+    params: {
+        "part_detail": true,
+        "status": "10-20",
+    }
+});
+
 $("#bom-invalid-table").on('load-success.bs.table', function() {
     var count = $("#bom-invalid-table").bootstrapTable('getData').length;
 
@@ -85,5 +101,11 @@ $("#low-stock-table").on('load-success.bs.table', function() {
     $("#low-stock-count").html(count);
 });
 
+$("#build-pending-table").on('load-success.bs.table', function() {
+    var count = $("#build-pending-table").bootstrapTable('getData').length;
+
+    $("#build-pending-count").html(count);
+});
+
 
 {% endblock %}
\ No newline at end of file
diff --git a/InvenTree/templates/InvenTree/low_stock.html b/InvenTree/templates/InvenTree/low_stock.html
index edafab1756..333dbded27 100644
--- a/InvenTree/templates/InvenTree/low_stock.html
+++ b/InvenTree/templates/InvenTree/low_stock.html
@@ -1,4 +1,4 @@
-{% extends "collapse.html" %}
+{% extends "collapse_index.html" %}
 
 {% load i18n %}
 
diff --git a/InvenTree/templates/InvenTree/starred_parts.html b/InvenTree/templates/InvenTree/starred_parts.html
index f852bf0f83..74f6edafb1 100644
--- a/InvenTree/templates/InvenTree/starred_parts.html
+++ b/InvenTree/templates/InvenTree/starred_parts.html
@@ -1,4 +1,4 @@
-{% extends "collapse.html" %}
+{% extends "collapse_index.html" %}
 
 {% load i18n %}
 
diff --git a/InvenTree/templates/js/build.html b/InvenTree/templates/js/build.html
index 8682e9bd81..10c017a776 100644
--- a/InvenTree/templates/js/build.html
+++ b/InvenTree/templates/js/build.html
@@ -13,7 +13,7 @@ function loadBuildTable(table, options) {
 
     setupFilterList("build", table);
 
-    table.inventreeTable({
+    $(table).inventreeTable({
         method: 'get',
         formatNoMatches: function() {
             return "{% trans "No builds matching query" %}";