2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-14 19:15:41 +00:00

Stock location part list now uses bootstrap table

- Serializers within serializers!
This commit is contained in:
Oliver
2018-05-02 23:08:45 +10:00
parent 211edb23bb
commit 1899d8f3e9
7 changed files with 135 additions and 78 deletions

View File

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

View File

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

View File

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

View File

@ -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' %}",
});