diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 18267f33c4..9a388c5b2c 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -15,6 +15,8 @@ from django.views import View from django.views.generic import UpdateView, CreateView, DeleteView from django.views.generic.base import TemplateView +from part.models import Part + from rest_framework import views @@ -287,6 +289,21 @@ class IndexView(TemplateView): template_name = 'InvenTree/index.html' + def get_context_data(self, **kwargs): + + context = super(TemplateView, self).get_context_data(**kwargs) + + # Generate a list of orderable parts which have stock below their minimum values + context['to_order'] = [part for part in Part.objects.filter(purchaseable=True) if part.need_to_restock()] + + # Generate a list of buildable parts which have stock below their minimum values + context['to_build'] = [part for part in Part.objects.filter(buildable=True) if part.need_to_restock()] + + print("order:", len(context['to_order'])) + print("build:", len(context['to_build'])) + + return context + class SearchView(TemplateView): """ View for InvenTree search page. diff --git a/InvenTree/build/templates/build/allocate.html b/InvenTree/build/templates/build/allocate.html index c3cda38429..0a3867af8e 100644 --- a/InvenTree/build/templates/build/allocate.html +++ b/InvenTree/build/templates/build/allocate.html @@ -11,12 +11,9 @@
{% for bom_item in bom_items.all %} -{% include "build/allocation_item.html" with item=bom_item build=build %} +{% include "build/allocation_item.html" with item=bom_item build=build collapse_id=bom_item.id %} {% endfor %} - -
-
diff --git a/InvenTree/build/templates/build/allocation_item.html b/InvenTree/build/templates/build/allocation_item.html index 9982457aca..f9e92a63a8 100644 --- a/InvenTree/build/templates/build/allocation_item.html +++ b/InvenTree/build/templates/build/allocation_item.html @@ -1,38 +1,32 @@ +{% extends "collapse.html" %} + {% load inventree_extras %} -
-
-
-
- -
- Required: -
-
- {% multiply build.quantity item.quantity %} -
-
- Allocated: -
-
- 0 -
-
-
- -
-
-
-
-
-
- -
-
-
+{% block collapse_title %} +{{ item.sub_part.name }} +{% endblock %} + +{% block collapse_heading %} +
+ Required:
-
\ No newline at end of file +
+ {% multiply build.quantity item.quantity %} +
+
+ Allocated: +
+
+ 0 +
+
+
+ +
+
+{% endblock %} + +{% block collapse_content %} + +
+{% endblock %} \ No newline at end of file diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index ab83b584cd..820df63955 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -193,14 +193,25 @@ class Part(models.Model): def available_stock(self): """ Return the total available stock. - This subtracts stock which is already allocated + + - This subtracts stock which is already allocated to builds """ total = self.total_stock total -= self.allocation_count - return max(total, 0) + return total + + def need_to_restock(self): + """ Return True if this part needs to be restocked + (either by purchasing or building). + + If the allocated_stock exceeds the total_stock, + then we need to restock. + """ + + return (self.total_stock - self.allocation_count) < self.minimum_stock @property def can_build(self): @@ -307,6 +318,12 @@ class Part(models.Model): def used_in_count(self): return self.used_in.count() + def required_parts(self): + parts = [] + for bom in self.bom_items.all(): + parts.append(bom.sub_part) + return parts + @property def supplier_count(self): # Return the number of supplier parts available for this part diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html index 3d514389bc..f199cc5981 100644 --- a/InvenTree/part/templates/part/category.html +++ b/InvenTree/part/templates/part/category.html @@ -33,9 +33,9 @@
-{% if category %} -{% include "part/subcategories.html" with children=category.children.all %} -{% else %} +{% if category and category.children.all|length > 0 %} +{% include "part/subcategories.html" with children=category.children.all collapse_id="children"%} +{% elif children|length > 0 %} {% include "part/subcategories.html" with children=children %} {% endif %}
diff --git a/InvenTree/part/templates/part/subcategories.html b/InvenTree/part/templates/part/subcategories.html index 5dcfa426ad..abf61d743e 100644 --- a/InvenTree/part/templates/part/subcategories.html +++ b/InvenTree/part/templates/part/subcategories.html @@ -1,27 +1,19 @@ -{% if children|length > 0 %} -
-
-
- -
-
-
    - {% for child in children %} -
  • - {{ child.name }} - {% if child.description %} - - {{ child.description }} - {% endif %} - {{ child.partcount }} -
  • - {% endfor %} -
-
-
-
-
-{% endif %} \ No newline at end of file +{% extends "collapse.html" %} + +{% block collapse_title %} +{{ children | length }} Child Categories +{% endblock %} + +{% block collapse_content %} + +{% endblock %} \ No newline at end of file diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 1483d8fc4f..76891ad4cd 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -31,10 +31,10 @@ -{% if location %} -{% include 'stock/location_list.html' with children=location.children.all %} -{% else %} -{% include 'stock/location_list.html' with children=locations %} +{% if location and location.children.all|length > 0 %} +{% include 'stock/location_list.html' with children=location.children.all collapse_id="locations" %} +{% elif locations|length > 0 %} +{% include 'stock/location_list.html' with children=locations collapse_id="locations" %} {% endif %}
diff --git a/InvenTree/stock/templates/stock/location_list.html b/InvenTree/stock/templates/stock/location_list.html index b906133e70..90d01c449c 100644 --- a/InvenTree/stock/templates/stock/location_list.html +++ b/InvenTree/stock/templates/stock/location_list.html @@ -1,23 +1,15 @@ -{% if children|length > 0 %} -
-
-
-
-

- Sub-Locations{{ children|length }} -

-
-
-
-
    - {% for child in children %} -
  • {{ child.name }} - {{ child.description }}
  • - {{ child.partcount }} - - {% endfor %} -
-
-
-
-
-{% endif %} \ No newline at end of file +{% extends "collapse.html" %} + +{% block collapse_title %} +Sub-Locations{{ children|length }} +{% 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 4150313bf9..91cac4c18c 100644 --- a/InvenTree/templates/InvenTree/index.html +++ b/InvenTree/templates/InvenTree/index.html @@ -3,9 +3,20 @@ {% block content %}

InvenTree

-

Index!

+{% if to_order %} +{% include "InvenTree/parts_to_order.html" with collapse_id="order" %} +{% endif %} + +{% if to_build %} +{% include "InvenTree/parts_to_build.html" with collapse_id="build" %} +{% endif %} {% endblock %} {% block js_load %} +{{ block.super }} +{% endblock %} + +{% block js_ready %} +{{ block.super }} {% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/InvenTree/parts_to_build.html b/InvenTree/templates/InvenTree/parts_to_build.html new file mode 100644 index 0000000000..e9c1dcdee1 --- /dev/null +++ b/InvenTree/templates/InvenTree/parts_to_build.html @@ -0,0 +1,14 @@ +{% extends "collapse.html" %} +{% block collapse_title %} +Parts to Build{{ to_build | length }} +{% endblock %} + +{% block collapse_heading %} +There are {{ to_build | length }} parts which need building. +{% endblock %} + +{% block collapse_content %} + +{% include "required_part_table.html" with parts=to_build table_id="to-build-table" %} + +{% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/InvenTree/parts_to_order.html b/InvenTree/templates/InvenTree/parts_to_order.html new file mode 100644 index 0000000000..b68eda7e14 --- /dev/null +++ b/InvenTree/templates/InvenTree/parts_to_order.html @@ -0,0 +1,14 @@ +{% extends "collapse.html" %} +{% block collapse_title %} +Parts to Order{{ to_order | length }} +{% endblock %} + +{% block collapse_heading %} +There are {{ to_order | length }} parts which need to be ordered. +{% endblock %} + +{% block collapse_content %} + +{% include "required_part_table.html" with parts=to_order table_id="to-order-table" %} + +{% endblock %} \ No newline at end of file diff --git a/InvenTree/templates/collapse.html b/InvenTree/templates/collapse.html new file mode 100644 index 0000000000..776c9cee35 --- /dev/null +++ b/InvenTree/templates/collapse.html @@ -0,0 +1,23 @@ +{% block collapse_preamble %} +{% endblock %} +
+
+
+
+ + {% block collapse_heading %} + {% endblock %} +
+
+
+
+ {% block collapse_content %} + {% endblock %} +
+
+
+
\ No newline at end of file diff --git a/InvenTree/templates/required_part_table.html b/InvenTree/templates/required_part_table.html new file mode 100644 index 0000000000..4ae1441f11 --- /dev/null +++ b/InvenTree/templates/required_part_table.html @@ -0,0 +1,18 @@ + + + + + + + + + {% for part in parts %} + + + + + + + + {% endfor %} +
PartDescriptionIn StockAllocatedNet Stock
{{ part.name }}{{ part.description }}{{ part.total_stock }}{{ part.allocation_count }}{{ part.available_stock }}
\ No newline at end of file