mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Stock location part list now uses bootstrap table
- Serializers within serializers!
This commit is contained in:
parent
211edb23bb
commit
1899d8f3e9
@ -34,8 +34,6 @@ apipatterns = [
|
||||
|
||||
urlpatterns = [
|
||||
|
||||
# API URL
|
||||
url(r'^api/', include(apipatterns)),
|
||||
# url(r'^api-doc/', include_docs_urls(title='InvenTree API')),
|
||||
|
||||
url(r'^part/', include(part_urls)),
|
||||
@ -50,6 +48,8 @@ urlpatterns = [
|
||||
url(r'^admin/', admin.site.urls),
|
||||
|
||||
url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||
|
||||
url(r'^api/', include(apipatterns)),
|
||||
]
|
||||
|
||||
# Static file access
|
||||
|
@ -1,6 +1,33 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from .models import Part
|
||||
from .models import Part, PartCategory
|
||||
|
||||
|
||||
class CategoryBriefSerializer(serializers.ModelSerializer):
|
||||
|
||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = PartCategory
|
||||
fields = [
|
||||
'pk',
|
||||
'name',
|
||||
'pathstring',
|
||||
'url',
|
||||
]
|
||||
|
||||
|
||||
class PartBriefSerializer(serializers.ModelSerializer):
|
||||
|
||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Part
|
||||
fields = [
|
||||
'pk',
|
||||
'url',
|
||||
'name',
|
||||
]
|
||||
|
||||
|
||||
class PartSerializer(serializers.ModelSerializer):
|
||||
@ -8,18 +35,7 @@ class PartSerializer(serializers.ModelSerializer):
|
||||
Used when displaying all details of a single component.
|
||||
"""
|
||||
|
||||
def _category_name(self, part):
|
||||
if part.category:
|
||||
return part.category.name
|
||||
return ''
|
||||
|
||||
def _category_url(self, part):
|
||||
if part.category:
|
||||
return part.category.get_absolute_url()
|
||||
return ''
|
||||
|
||||
category_name = serializers.SerializerMethodField('_category_name')
|
||||
category_url = serializers.SerializerMethodField('_category_url')
|
||||
category = CategoryBriefSerializer(many=False, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Part
|
||||
@ -31,8 +47,6 @@ class PartSerializer(serializers.ModelSerializer):
|
||||
'URL', # Link to an external URL (optional)
|
||||
'description',
|
||||
'category',
|
||||
'category_name',
|
||||
'category_url',
|
||||
'total_stock',
|
||||
'available_stock',
|
||||
'units',
|
||||
|
@ -40,10 +40,15 @@
|
||||
{% if category == None %}
|
||||
{
|
||||
sortable: true,
|
||||
field: 'category_name',
|
||||
field: 'category',
|
||||
title: 'Category',
|
||||
formatter: function(value, row, index, field) {
|
||||
return renderLink(value, row.category_url)
|
||||
if (row.category) {
|
||||
return renderLink(row.category.name, row.category.url);
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
},
|
||||
{% endif %}
|
||||
|
@ -2,10 +2,30 @@ from rest_framework import serializers
|
||||
|
||||
from .models import StockItem, StockLocation
|
||||
|
||||
from part.serializers import PartBriefSerializer
|
||||
|
||||
|
||||
class LocationBriefSerializer(serializers.ModelSerializer):
|
||||
|
||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = StockLocation
|
||||
fields = [
|
||||
'pk',
|
||||
'name',
|
||||
'pathstring',
|
||||
'url',
|
||||
]
|
||||
|
||||
|
||||
class StockItemSerializer(serializers.ModelSerializer):
|
||||
""" Serializer for a StockItem
|
||||
"""
|
||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||
|
||||
part = PartBriefSerializer(many=False, read_only=True)
|
||||
location = LocationBriefSerializer(many=False, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = StockItem
|
||||
@ -16,17 +36,17 @@ class StockItemSerializer(serializers.ModelSerializer):
|
||||
'supplier_part',
|
||||
'location',
|
||||
'in_stock',
|
||||
'belongs_to',
|
||||
'customer',
|
||||
#'belongs_to',
|
||||
#'customer',
|
||||
'quantity',
|
||||
'serial',
|
||||
'batch',
|
||||
'status',
|
||||
'notes',
|
||||
'updated',
|
||||
'stocktake_date',
|
||||
'stocktake_user',
|
||||
'review_needed',
|
||||
#'updated',
|
||||
#'stocktake_date',
|
||||
#'stocktake_user',
|
||||
#'review_needed',
|
||||
]
|
||||
|
||||
""" These fields are read-only in this context.
|
||||
|
@ -9,35 +9,7 @@
|
||||
{% include "stock/location_list.html" with locations=locations %}
|
||||
{% endif %}
|
||||
|
||||
<table class="table table-striped" id='stock-table' data-filtering='true' data-sorting='true'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Part</th>
|
||||
<th>Location</th>
|
||||
<th data-type='number'>Stock</th>
|
||||
<th>Status</th>
|
||||
<th data-type='date'>Stocktake</th>
|
||||
<th data-sortable='false'></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in items.all %}
|
||||
<tr>
|
||||
<td><a href="{% url 'part-stock' item.part.id %}">{{ item.part.name }}</a></td>
|
||||
<td>
|
||||
{% if item.location %}
|
||||
<a href="{% url 'stock-location-detail' item.location.id %}">
|
||||
{{ item.location.pathstring }}
|
||||
</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ item.quantity }}</td>
|
||||
<td>{{ item.get_status_display }}</td>
|
||||
<td>{{ item.stocktake_date }}</td>
|
||||
<td><a href="{% url 'stock-item-detail' item.id %}">Click</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
<table class="table table-striped" id='stock-table'>
|
||||
</table>
|
||||
|
||||
<div class='container-fluid'>
|
||||
@ -60,4 +32,7 @@
|
||||
follow: true
|
||||
});
|
||||
});
|
||||
|
||||
{% include "stock/stock_table.html" %}
|
||||
|
||||
{% endblock %}
|
@ -12,8 +12,10 @@
|
||||
{% include "stock/location_list.html" with locations=location.children %}
|
||||
{% endif %}
|
||||
|
||||
<h4>Stock Items</h4>
|
||||
{% include "stock/stock_table.html" with items=location.items %}
|
||||
{% if location.has_items %}
|
||||
<table class='table table-striped table-condensed' id='stock-table'>
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
<div class='container-fluid'>
|
||||
<button class='btn btn-success' id='location-create'>New Stock Location</button>
|
||||
@ -69,4 +71,7 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
{% include 'stock/stock_table.html' with location=location %}
|
||||
|
||||
{% endblock %}
|
||||
|
@ -1,22 +1,60 @@
|
||||
<table class="table table-striped" id='stock-table' data-filtering='true' data-sorting='true'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Part</th>
|
||||
<th data-type='number'>Stock</th>
|
||||
<th>Status</th>
|
||||
<th>Stocktake</th>
|
||||
<th data-sortable='false'></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in items.all %}
|
||||
<tr>
|
||||
<td><a href="{% url 'part-stock' item.part.id %}">{{ item.part.name }}</a></td>
|
||||
<td>{{ item.quantity }}</td>
|
||||
<td>{{ item.get_status_display }}</td>
|
||||
<td>{{ item.stocktake_date }}</td>
|
||||
<td><a href="{% url 'stock-item-detail' item.id %}">Click</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
$("#stock-table").bootstrapTable({
|
||||
sortable: true,
|
||||
search: true,
|
||||
method: 'get',
|
||||
pagination: true,
|
||||
rememberOrder: true,
|
||||
{% if location %}
|
||||
queryParams: function(p) {
|
||||
return {
|
||||
location: {{ location.id }}
|
||||
}
|
||||
},
|
||||
{% endif %}
|
||||
columns: [
|
||||
{
|
||||
checkbox: true,
|
||||
title: 'Select',
|
||||
searchable: false,
|
||||
},
|
||||
{
|
||||
field: 'pk',
|
||||
title: 'ID',
|
||||
visible: false,
|
||||
},
|
||||
{
|
||||
field: 'part.name',
|
||||
title: 'Part',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
return renderLink(value, row.part.url);
|
||||
}
|
||||
},
|
||||
{% if location == None %}
|
||||
{
|
||||
field: 'location',
|
||||
title: 'Location',
|
||||
sortable: true,
|
||||
formatter: function(value, row, index, field) {
|
||||
if (row.location) {
|
||||
return renderLink(row.location.name, row.location.url);
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
},
|
||||
{% endif %}
|
||||
{
|
||||
field: 'quantity',
|
||||
title: 'Stock',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: 'Status',
|
||||
sortable: true,
|
||||
}
|
||||
],
|
||||
url: "{% url 'api-stock-list' %}",
|
||||
});
|
Loading…
Reference in New Issue
Block a user