mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 13:28:49 +00:00
Added helper functions, improved UI
This commit is contained in:
parent
a67d5b58db
commit
937470750b
@ -90,6 +90,10 @@ class InvenTreeTree(models.Model):
|
|||||||
|
|
||||||
return unique
|
return unique
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_children(self):
|
||||||
|
return self.children.count() > 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def children(self):
|
def children(self):
|
||||||
contents = ContentType.objects.get_for_model(type(self))
|
contents = ContentType.objects.get_for_model(type(self))
|
||||||
|
@ -35,11 +35,9 @@ class PartCategory(InvenTreeTree):
|
|||||||
|
|
||||||
return count
|
return count
|
||||||
|
|
||||||
"""
|
|
||||||
@property
|
@property
|
||||||
def parts(self):
|
def has_parts(self):
|
||||||
return self.part_set.all()
|
return self.parts.count() > 0
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
@receiver(pre_delete, sender=PartCategory, dispatch_uid='partcategory_delete_log')
|
@receiver(pre_delete, sender=PartCategory, dispatch_uid='partcategory_delete_log')
|
||||||
@ -186,16 +184,16 @@ class Part(models.Model):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def bom_count(self):
|
def bom_count(self):
|
||||||
return self.bom_items.all().count()
|
return self.bom_items.count()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def used_in_count(self):
|
def used_in_count(self):
|
||||||
return self.used_in.all().count()
|
return self.used_in.count()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supplier_count(self):
|
def supplier_count(self):
|
||||||
# Return the number of supplier parts available for this part
|
# Return the number of supplier parts available for this part
|
||||||
return self.supplier_parts.all().count()
|
return self.supplier_parts.count()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@property
|
@property
|
||||||
|
@ -11,9 +11,15 @@
|
|||||||
<i>{{ category.description }}</i>
|
<i>{{ category.description }}</i>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
{% if category.has_children %}
|
||||||
|
<h4>Subcategories</h4>
|
||||||
{% include "part/category_subcategories.html" with children=category.children.all %}
|
{% 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 %}
|
{% include "part/category_parts.html" with parts=category.parts.all %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class='container-fluid'>
|
<div class='container-fluid'>
|
||||||
<a href="{% url 'category-create' %}?category={{ category.id }}">
|
<a href="{% url 'category-create' %}?category={{ category.id }}">
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
{% if parts|length > 0 %}
|
|
||||||
Parts:
|
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Part</th>
|
<th>Part</th>
|
||||||
@ -11,5 +9,4 @@ Parts:
|
|||||||
<td>{{ part.description }}</td>
|
<td>{{ part.description }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
{% endif %}
|
|
@ -1,5 +1,3 @@
|
|||||||
{% if children|length > 0 %}
|
|
||||||
Subcategories:
|
|
||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
{% for child in children %}
|
{% for child in children %}
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
@ -10,5 +8,4 @@ Subcategories:
|
|||||||
<span class='badge'>{{ child.partcount }}</span>
|
<span class='badge'>{{ child.partcount }}</span>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
|
@ -5,9 +5,15 @@
|
|||||||
|
|
||||||
{% include "part/cat_link.html" with category=category %}
|
{% 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 %}
|
{% 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 %}
|
{% include "part/category_parts.html" with parts=parts %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class='container-fluid'>
|
<div class='container-fluid'>
|
||||||
<a href="{% url 'category-create' %}">
|
<a href="{% url 'category-create' %}">
|
||||||
|
@ -26,8 +26,11 @@ class StockLocation(InvenTreeTree):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def items(self):
|
def items(self):
|
||||||
stock_list = self.stockitem_set.all()
|
return self.stockitem_set.all()
|
||||||
return stock_list
|
|
||||||
|
@property
|
||||||
|
def has_items(self):
|
||||||
|
return self.items.count() > 0
|
||||||
|
|
||||||
|
|
||||||
@receiver(pre_delete, sender=StockLocation, dispatch_uid='stocklocation_delete_log')
|
@receiver(pre_delete, sender=StockLocation, dispatch_uid='stocklocation_delete_log')
|
||||||
@ -60,7 +63,6 @@ class StockItem(models.Model):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return '/stock/item/{id}/'.format(id=self.id)
|
return '/stock/item/{id}/'.format(id=self.id)
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = [
|
unique_together = [
|
||||||
('part', 'serial'),
|
('part', 'serial'),
|
||||||
@ -138,7 +140,7 @@ class StockItem(models.Model):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def has_tracking_info(self):
|
def has_tracking_info(self):
|
||||||
return self.tracking_info.all().count() > 0
|
return self.tracking_info.count() > 0
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def stocktake(self, count, user):
|
def stocktake(self, count, user):
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
{% include "stock/loc_link.html" with location=None %}
|
{% include "stock/loc_link.html" with location=None %}
|
||||||
|
|
||||||
{% if locations.all|length > 0 %}
|
{% if locations.all|length > 0 %}
|
||||||
|
<h4>Storage Locations</h4>
|
||||||
{% include "stock/location_list.html" with locations=locations %}
|
{% include "stock/location_list.html" with locations=locations %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -4,15 +4,18 @@
|
|||||||
|
|
||||||
{% include "stock/loc_link.html" with location=location %}
|
{% include "stock/loc_link.html" with location=location %}
|
||||||
|
|
||||||
<p>
|
<h3>{{ location.name }}</h3>
|
||||||
<b>{{ location.name }}</b><br>
|
<p>{{ location.description }}</p>
|
||||||
<i>{{ location.description }}</i>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
|
|
||||||
|
{% if location.has_children %}
|
||||||
|
<h4>Sub Locations</h4>
|
||||||
{% include "stock/location_list.html" with locations=location.children %}
|
{% 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 %}
|
{% include "stock/stock_table.html" with items=location.items %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class='container-fluid'>
|
<div class='container-fluid'>
|
||||||
<a href="{% url 'stock-location-create' %}?location={{ location.id }}">
|
<a href="{% url 'stock-location-create' %}?location={{ location.id }}">
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
Storage locations:
|
|
||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
{% for child in locations.all %}
|
{% for child in locations.all %}
|
||||||
<li class="list-group-item"><a href="{% url 'stock-location-detail' child.id %}">{{ child.name }}</a></li>
|
<li class="list-group-item"><a href="{% url 'stock-location-detail' child.id %}">{{ child.name }}</a></li>
|
||||||
|
@ -14,6 +14,14 @@ class Supplier(Company):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return "/supplier/{id}/".format(id=self.id)
|
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):
|
class Manufacturer(Company):
|
||||||
""" Represents a manfufacturer
|
""" Represents a manfufacturer
|
||||||
|
@ -5,12 +5,12 @@ Are you sure you want to delete supplier '{{ supplier.name }}'?
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block del_body %}
|
{% block del_body %}
|
||||||
{% if supplier.parts.all|length > 0 %}
|
{% if supplier.part_count > 0 %}
|
||||||
<p>There are {{ supplier.parts.all|length }} parts sourced from this supplier.<br>
|
<p>There are {{ supplier.part_count }} parts sourced from this supplier.<br>
|
||||||
If this supplier is deleted, these child categories will also be deleted.</p>
|
If this supplier is deleted, these supplier part entries will also be deleted.</p>
|
||||||
<ul class='list-group'>
|
<ul class='list-group'>
|
||||||
{% for part in supplier.parts.all %}
|
{% 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 %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user