Merge pull request #203 from SchrodingersGat/front-page

Improvements for the index/landing page
This commit is contained in:
Oliver 2019-05-02 20:51:22 +10:00 committed by GitHub
commit 592a009b36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 188 additions and 99 deletions

View File

@ -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.

View File

@ -11,12 +11,9 @@
<hr>
{% 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 %}
<table class='table table-striped' id='build-table'>
</table>
<div>
<button class='btn btn-warning' type='button' id='complete-build'>Complete Build</button>
</div>

View File

@ -1,15 +1,13 @@
{% extends "collapse.html" %}
{% load inventree_extras %}
<div class='panel-group'>
<div class='panel pane-default'>
<div class='panel panel-heading'>
<div class='row'>
<div class='col-sm-6'>
<div class='panel-title'>
<a data-toggle='collapse' href='#collapse-item-{{ item.id }}'>{{ item.sub_part.name }}</a>
</div>
</div>
<div class='col-sm-1' align='right'>
{% block collapse_title %}
{{ item.sub_part.name }}
{% endblock %}
{% block collapse_heading %}
<div class='col-sm-1' align='right'>
Required:
</div>
<div class='col-sm-1'>
@ -25,14 +23,10 @@
<div class='btn-group' style='float: right;'>
<button class='btn btn-success btn-sm' id='new-item-{{ item.sub_part.id }}' url="{% url 'build-item-create' %}?part={{ item.sub_part.id }}&build={{ build.id }}">Allocate Parts</button>
</div>
</div>
</div>
</div>
<div id='collapse-item-{{ item.id }}' class='panel-collapse collapse'>
<div class='panel-body'>
<table class='table table-striped table-condensed' id='allocate-table-id-{{ item.sub_part.id }}'>
</table>
</div>
</div>
</div>
</div>
{% endblock %}
{% block collapse_content %}
<table class='table table-striped table-condensed' id='allocate-table-id-{{ item.sub_part.id }}'>
</table>
{% endblock %}

View File

@ -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

View File

@ -33,9 +33,9 @@
</div>
</div>
{% 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 %}
<hr>

View File

@ -1,27 +1,19 @@
{% if children|length > 0 %}
<hr>
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" href="#collapse1">{{ children | length }} Child Categories</a>
</h4>
</div>
<div id="collapse1" class="panel-collapse collapse">
<div class="panel-body">
<ul class="list-group">
{% for child in children %}
<li class="list-group-item">
{% extends "collapse.html" %}
{% block collapse_title %}
{{ children | length }} Child Categories
{% endblock %}
{% block collapse_content %}
<ul class="list-group">
{% for child in children %}
<li class="list-group-item">
<b><a href="{% url 'category-detail' child.id %}">{{ child.name }}</a></b>
{% if child.description %}
<i> - {{ child.description }}</i>
{% endif %}
<span class='badge'>{{ child.partcount }}</span>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
{% endif %}
</li>
{% endfor %}
</ul>
{% endblock %}

View File

@ -31,10 +31,10 @@
</div>
</div>
{% 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 %}
<hr>

View File

@ -1,23 +1,15 @@
{% if children|length > 0 %}
<hr>
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" href="#collapse1">Sub-Locations</a><span class='badge'>{{ children|length }}</span>
</h4>
</div>
<div id="collapse1" class="panel-collapse collapse">
<div class="panel-body">
<ul class="list-group">
{% for child in children %}
<li class="list-group-item"><a href="{% url 'stock-location-detail' child.id %}">{{ child.name }}</a> - <i>{{ child.description }}</i></li>
{% extends "collapse.html" %}
{% block collapse_title %}
Sub-Locations<span class='badge'>{{ children|length }}</span>
{% endblock %}
{% block collapse_content %}
<ul class="list-group">
{% for child in children %}
<li class="list-group-item"><a href="{% url 'stock-location-detail' child.id %}">{{ child.name }}</a> - <i>{{ child.description }}</i></li>
<span class='badge'>{{ child.partcount }}</span>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
{% endif %}
</li>
{% endfor %}
</ul>
{% endblock %}

View File

@ -3,9 +3,20 @@
{% block content %}
<h3>InvenTree</h3>
<p>Index!</p>
{% 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 %}

View File

@ -0,0 +1,14 @@
{% extends "collapse.html" %}
{% block collapse_title %}
Parts to Build<span class='badge'>{{ to_build | length }}</span>
{% 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 %}

View File

@ -0,0 +1,14 @@
{% extends "collapse.html" %}
{% block collapse_title %}
Parts to Order<span class='badge'>{{ to_order | length }}</span>
{% 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 %}

View File

@ -0,0 +1,23 @@
{% block collapse_preamble %}
{% endblock %}
<div class='panel-group'>
<div class='panel panel-default'>
<div class='panel panel-heading'>
<div class='row'>
<div class='col-sm-6'>
<div class='panel-title'>
<a data-toggle='collapse' href="#collapse-item-{{ collapse_id }}">{% block collapse_title %}Title{% endblock %}</a>
</div>
</div>
{% block collapse_heading %}
{% endblock %}
</div>
</div>
<div class='panel-collapse collapse' id='collapse-item-{{ collapse_id }}'>
<div class='panel-body'>
{% block collapse_content %}
{% endblock %}
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,18 @@
<table class='table table-striped table-condensed' id='{{ table_id }}'>
<tr>
<th>Part</th>
<th>Description</th>
<th>In Stock</th>
<th>Allocated</th>
<th>Net Stock</th>
</tr>
{% for part in parts %}
<tr>
<td><a href="{% url 'part-detail' part.id %}">{{ part.name }}</a></td>
<td>{{ part.description }}</td>
<td>{{ part.total_stock }}</td>
<td>{{ part.allocation_count }}</td>
<td>{{ part.available_stock }}</td>
</tr>
{% endfor %}
</table>