Added helper functions, improved UI

This commit is contained in:
Oliver 2018-04-16 23:26:02 +10:00
parent a67d5b58db
commit 937470750b
12 changed files with 50 additions and 29 deletions

View File

@ -90,6 +90,10 @@ class InvenTreeTree(models.Model):
return unique
@property
def has_children(self):
return self.children.count() > 0
@property
def children(self):
contents = ContentType.objects.get_for_model(type(self))

View File

@ -35,11 +35,9 @@ class PartCategory(InvenTreeTree):
return count
"""
@property
def parts(self):
return self.part_set.all()
"""
def has_parts(self):
return self.parts.count() > 0
@receiver(pre_delete, sender=PartCategory, dispatch_uid='partcategory_delete_log')
@ -186,16 +184,16 @@ class Part(models.Model):
@property
def bom_count(self):
return self.bom_items.all().count()
return self.bom_items.count()
@property
def used_in_count(self):
return self.used_in.all().count()
return self.used_in.count()
@property
def supplier_count(self):
# Return the number of supplier parts available for this part
return self.supplier_parts.all().count()
return self.supplier_parts.count()
"""
@property

View File

@ -11,9 +11,15 @@
<i>{{ category.description }}</i>
</p>
{% if category.has_children %}
<h4>Subcategories</h4>
{% include "part/category_subcategories.html" with children=category.children.all %}
{% endif %}
{% if category.has_parts %}
<h4>Parts</h4>
{% include "part/category_parts.html" with parts=category.parts.all %}
{% endif %}
<div class='container-fluid'>
<a href="{% url 'category-create' %}?category={{ category.id }}">

View File

@ -1,5 +1,3 @@
{% if parts|length > 0 %}
Parts:
<table class="table table-striped">
<tr>
<th>Part</th>
@ -11,5 +9,4 @@ Parts:
<td>{{ part.description }}</td>
</tr>
{% endfor %}
</table>
{% endif %}
</table>

View File

@ -1,5 +1,3 @@
{% if children|length > 0 %}
Subcategories:
<ul class="list-group">
{% for child in children %}
<li class="list-group-item">
@ -10,5 +8,4 @@ Subcategories:
<span class='badge'>{{ child.partcount }}</span>
</li>
{% endfor %}
</ul>
{% endif %}
</ul>

View File

@ -5,9 +5,15 @@
{% include "part/cat_link.html" with category=category %}
{% if children.all|length > 0 %}
<h4>Part Categories</h4>
{% include "part/category_subcategories.html" with children=children %}
{% endif %}
{% if parts.all|length > 0%}
<h4>Top Level Parts</h4>
{% include "part/category_parts.html" with parts=parts %}
{% endif %}
<div class='container-fluid'>
<a href="{% url 'category-create' %}">

View File

@ -26,8 +26,11 @@ class StockLocation(InvenTreeTree):
@property
def items(self):
stock_list = self.stockitem_set.all()
return stock_list
return self.stockitem_set.all()
@property
def has_items(self):
return self.items.count() > 0
@receiver(pre_delete, sender=StockLocation, dispatch_uid='stocklocation_delete_log')
@ -60,7 +63,6 @@ class StockItem(models.Model):
def get_absolute_url(self):
return '/stock/item/{id}/'.format(id=self.id)
class Meta:
unique_together = [
('part', 'serial'),
@ -138,7 +140,7 @@ class StockItem(models.Model):
@property
def has_tracking_info(self):
return self.tracking_info.all().count() > 0
return self.tracking_info.count() > 0
@transaction.atomic
def stocktake(self, count, user):

View File

@ -5,6 +5,7 @@
{% include "stock/loc_link.html" with location=None %}
{% if locations.all|length > 0 %}
<h4>Storage Locations</h4>
{% include "stock/location_list.html" with locations=locations %}
{% endif %}

View File

@ -4,15 +4,18 @@
{% include "stock/loc_link.html" with location=location %}
<p>
<b>{{ location.name }}</b><br>
<i>{{ location.description }}</i>
</p>
<h3>{{ location.name }}</h3>
<p>{{ location.description }}</p>
{% if location.has_children %}
<h4>Sub Locations</h4>
{% include "stock/location_list.html" with locations=location.children %}
{% endif %}
{% if location.has_items %}
<h4>Stock Items</h4>
{% include "stock/stock_table.html" with items=location.items %}
{% endif %}
<div class='container-fluid'>
<a href="{% url 'stock-location-create' %}?location={{ location.id }}">

View File

@ -1,4 +1,3 @@
Storage locations:
<ul class="list-group">
{% for child in locations.all %}
<li class="list-group-item"><a href="{% url 'stock-location-detail' child.id %}">{{ child.name }}</a></li>

View File

@ -14,6 +14,14 @@ class Supplier(Company):
def get_absolute_url(self):
return "/supplier/{id}/".format(id=self.id)
@property
def part_count(self):
return self.parts.count()
@property
def has_parts(self):
return self.part_count > 0
class Manufacturer(Company):
""" Represents a manfufacturer

View File

@ -5,12 +5,12 @@ Are you sure you want to delete supplier '{{ supplier.name }}'?
{% endblock %}
{% block del_body %}
{% if supplier.parts.all|length > 0 %}
<p>There are {{ supplier.parts.all|length }} parts sourced from this supplier.<br>
If this supplier is deleted, these child categories will also be deleted.</p>
{% if supplier.part_count > 0 %}
<p>There are {{ supplier.part_count }} parts sourced from this supplier.<br>
If this supplier is deleted, these supplier part entries will also be deleted.</p>
<ul class='list-group'>
{% for part in supplier.parts.all %}
<li class='list-group-item'><b>{{ part.SKU }}</b><i>Part - {{ part.part.name }}</i></li>
<li class='list-group-item'><b>{{ part.SKU }}</b><br><i>Part - {{ part.part.name }}</i></li>
{% endfor %}
</ul>
{% endif %}