mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-11 09:48:50 +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 rest_framework import serializers
|
||||||
from InvenTree.serializers import InvenTreeModelSerializer
|
from InvenTree.serializers import InvenTreeModelSerializer
|
||||||
|
from stock.serializers import StockItemSerializerBrief
|
||||||
|
|
||||||
from .models import Build, BuildItem
|
from .models import Build, BuildItem
|
||||||
|
|
||||||
@ -35,7 +36,8 @@ class BuildItemSerializer(InvenTreeModelSerializer):
|
|||||||
""" Serializes a BuildItem object """
|
""" Serializes a BuildItem object """
|
||||||
|
|
||||||
part = serializers.IntegerField(source='stock_item.part.pk', read_only=True)
|
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:
|
class Meta:
|
||||||
model = BuildItem
|
model = BuildItem
|
||||||
@ -45,5 +47,6 @@ class BuildItemSerializer(InvenTreeModelSerializer):
|
|||||||
'part',
|
'part',
|
||||||
'part_name',
|
'part_name',
|
||||||
'stock_item',
|
'stock_item',
|
||||||
|
'stock_item_detail',
|
||||||
'quantity'
|
'quantity'
|
||||||
]
|
]
|
||||||
|
@ -18,16 +18,45 @@
|
|||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
<script src="{% static 'script/inventree/api.js' %}"></script>
|
<script src="{% static 'script/inventree/api.js' %}"></script>
|
||||||
<script src="{% static 'script/inventree/part.js' %}"></script>
|
<script src="{% static 'script/inventree/part.js' %}"></script>
|
||||||
|
<script src="{% static 'script/inventree/build.js' %}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block js_ready %}
|
{% block js_ready %}
|
||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
|
|
||||||
|
function makeInnerTable(pk) {
|
||||||
|
var table = "<table class='table table-striped' id='part-table-" + pk + "'></table>";
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
$('#build-table').bootstrapTable({
|
$('#build-table').bootstrapTable({
|
||||||
sortable: true,
|
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: '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: [
|
columns: [
|
||||||
{
|
{
|
||||||
field: 'sub_part.name',
|
field: 'sub_part_detail.name',
|
||||||
title: 'Part',
|
title: 'Part',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -36,7 +65,7 @@
|
|||||||
{
|
{
|
||||||
field: 'quantity',
|
field: 'quantity',
|
||||||
title: 'Quantity',
|
title: 'Quantity',
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -15,5 +15,5 @@ function getPartList(filters={}, options={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getBomList(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):
|
class StockItemSerializer(serializers.ModelSerializer):
|
||||||
""" Serializer for a StockItem:
|
""" Serializer for a StockItem:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user