mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
First pass at build allocation table
- Uses bootstrap-table "detailView" function
This commit is contained in:
parent
192f604b76
commit
5c5411132a
@ -7,6 +7,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from rest_framework import serializers
|
||||
from InvenTree.serializers import InvenTreeModelSerializer
|
||||
from stock.serializers import StockItemSerializerBrief
|
||||
|
||||
from .models import Build, BuildItem
|
||||
|
||||
@ -35,7 +36,8 @@ class BuildItemSerializer(InvenTreeModelSerializer):
|
||||
""" Serializes a BuildItem object """
|
||||
|
||||
part = serializers.IntegerField(source='stock_item.part.pk', read_only=True)
|
||||
part_name = serializers.CharField(source='stock_item.part', read_only=True)
|
||||
part_name = serializers.CharField(source='stock_item.part.name', read_only=True)
|
||||
stock_item_detail = StockItemSerializerBrief(source='stock_item', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = BuildItem
|
||||
@ -45,5 +47,6 @@ class BuildItemSerializer(InvenTreeModelSerializer):
|
||||
'part',
|
||||
'part_name',
|
||||
'stock_item',
|
||||
'stock_item_detail',
|
||||
'quantity'
|
||||
]
|
||||
|
@ -18,16 +18,45 @@
|
||||
{{ block.super }}
|
||||
<script src="{% static 'script/inventree/api.js' %}"></script>
|
||||
<script src="{% static 'script/inventree/part.js' %}"></script>
|
||||
<script src="{% static 'script/inventree/build.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block js_ready %}
|
||||
{{ block.super }}
|
||||
|
||||
function makeInnerTable(pk) {
|
||||
var table = "<table class='table table-striped' id='part-table-" + pk + "'></table>";
|
||||
return table;
|
||||
}
|
||||
|
||||
$('#build-table').bootstrapTable({
|
||||
sortable: true,
|
||||
detailView: true,
|
||||
detailFormatter: function(index, row, element) {
|
||||
return makeInnerTable(row.pk);
|
||||
},
|
||||
onExpandRow: function(index, row, $detail) {
|
||||
$('#part-table-' + row.pk).bootstrapTable({
|
||||
columns: [
|
||||
{
|
||||
field: 'sub_part.name',
|
||||
field: 'stock_item_detail.location_name',
|
||||
title: 'Location',
|
||||
},
|
||||
{
|
||||
field: 'stock_item_detail.quantity',
|
||||
title: 'Available',
|
||||
},
|
||||
{
|
||||
field: 'quantity',
|
||||
title: 'Allocated',
|
||||
},
|
||||
],
|
||||
url: "/api/build/item/?build={{ build.pk }}&part=" + row.sub_part,
|
||||
});
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'sub_part_detail.name',
|
||||
title: 'Part',
|
||||
},
|
||||
{
|
||||
@ -36,7 +65,7 @@
|
||||
{
|
||||
field: 'quantity',
|
||||
title: 'Quantity',
|
||||
}
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
|
@ -15,5 +15,5 @@ function getPartList(filters={}, options={}) {
|
||||
}
|
||||
|
||||
function getBomList(filters={}, options={}) {
|
||||
return inventreeGet('/api/part/bom/', filters, options);
|
||||
return inventreeGet('/api/bom/', filters, options);
|
||||
}
|
@ -47,6 +47,24 @@ class StockItemSerializerBrief(serializers.ModelSerializer):
|
||||
]
|
||||
|
||||
|
||||
class StockItemSerializerBrief(serializers.ModelSerializer):
|
||||
""" Brief serializers for a StockItem """
|
||||
|
||||
location_name = serializers.CharField(source='location', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = StockItem
|
||||
fields = [
|
||||
'pk',
|
||||
'uuid',
|
||||
'part',
|
||||
'supplier_part',
|
||||
'location',
|
||||
'location_name',
|
||||
'quantity',
|
||||
]
|
||||
|
||||
|
||||
class StockItemSerializer(serializers.ModelSerializer):
|
||||
""" Serializer for a StockItem:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user