Switch between display and edit mode for build allocations

This commit is contained in:
Oliver Walters 2019-05-27 08:07:38 +10:00
parent 59fa59f760
commit a305301b95
8 changed files with 100 additions and 34 deletions

View File

@ -70,6 +70,10 @@ class BuildItemList(generics.ListCreateAPIView):
query = BuildItem.objects.all()
query = query.select_related('stock_item')
query = query.prefetch_related('stock_item__part')
query = query.prefetch_related('stock_item__part__category')
if part_pk:
query = query.filter(stock_item__part=part_pk)

View File

@ -45,6 +45,7 @@ class BuildItemSerializer(InvenTreeModelSerializer):
part = serializers.IntegerField(source='stock_item.part.pk', read_only=True)
part_name = serializers.CharField(source='stock_item.part.full_name', read_only=True)
part_image = serializers.CharField(source='stock_item.part.image.url', read_only=True)
stock_item_detail = StockItemSerializerBrief(source='stock_item', read_only=True)
class Meta:
@ -54,6 +55,7 @@ class BuildItemSerializer(InvenTreeModelSerializer):
'build',
'part',
'part_name',
'part_image',
'stock_item',
'stock_item_detail',
'quantity'

View File

@ -10,39 +10,11 @@ InvenTree | Allocate Parts
{% include "build/tabs.html" with tab='allocate' %}
<h4>Allocate Parts for Build</h4>
<div class='row'>
<div class='col-sm-6'>
</div>
<div class='col-sm-6'>
<div class='btn-group' style='float: right;'>
<button class='btn btn-primary' type='button' title='Automatic allocation' id='auto-allocate-build'>Auto Allocate</button>
<button class='btn btn-warning' type='button' title='Unallocate build stock' id='unallocate-build'>Unallocate</button>
</div>
</div>
</div>
<hr>
<div class='row'>
<div class='col-sm-6'>
<h4>Part</h4>
</div>
<div class='col-sm-2'>
<h4>Available</h4>
</div>
<div class='col-sm-2'>
<h4>Required</h4>
</div>
<div class='col-sm-2'>
<h4>Allocated</h4>
</div>
</div>
{% for bom_item in bom_items.all %}
{% include "build/allocation_item.html" with item=bom_item build=build collapse_id=bom_item.id %}
{% endfor %}
{% if editing %}
{% include "build/allocate_edit.html" %}
{% else %}
{% include "build/allocate_view.html" %}
{% endif %}
{% endblock %}
@ -55,6 +27,8 @@ InvenTree | Allocate Parts
{% block js_ready %}
{{ block.super }}
{% if editing %}
{% for bom_item in bom_items.all %}
loadAllocationTable(
@ -86,4 +60,37 @@ InvenTree | Allocate Parts
);
});
{% else %}
$("#build-item-table").bootstrapTable({
url: "{% url 'api-build-item-list' %}",
queryParams: {
build: {{ build.id }},
},
search: true,
columns: [
{
field: 'part_name',
title: 'Part',
formatter: function(value, row, index, field) {
return imageHoverIcon(row.part_image) + value;
}
},
{
field: 'stock_item_detail.location_name',
title: 'Location',
},
{
field: 'quantity',
title: 'Quantity Allocated',
},
]
});
$("#btn-allocate").click(function() {
location.href = "{% url 'build-allocate' build.id %}?edit=1";
});
{% endif %}
{% endblock %}

View File

@ -0,0 +1,32 @@
<h4>Allocate Stock to Build</h4>
<div class='row'>
<div class='col-sm-6'>
</div>
<div class='col-sm-6'>
<div class='btn-group' style='float: right;'>
<button class='btn btn-primary' type='button' title='Automatic allocation' id='auto-allocate-build'>Auto Allocate</button>
<button class='btn btn-warning' type='button' title='Unallocate build stock' id='unallocate-build'>Unallocate</button>
</div>
</div>
</div>
<hr>
<div class='row'>
<div class='col-sm-6'>
<h4>Part</h4>
</div>
<div class='col-sm-2'>
<h4>Available</h4>
</div>
<div class='col-sm-2'>
<h4>Required</h4>
</div>
<div class='col-sm-2'>
<h4>Allocated</h4>
</div>
</div>
{% for bom_item in bom_items.all %}
{% include "build/allocation_item.html" with item=bom_item build=build collapse_id=bom_item.id %}
{% endfor %}

View File

@ -0,0 +1,10 @@
<h4>Stock Allocated to Build</h4>
<div id='#build-item-toolbar'>
<div class='btn-group'>
<button class='btn btn-primary' type='button' id='btn-allocate' title='Allocate Stock'>Allocate</button>
</div>
</div>
<table class='table table-condensed table-striped' id='build-item-table' data-toolbar='#build-item-toolbar'>
</table>

View File

@ -33,4 +33,12 @@
</tbody>
</table>
{% endblock %}
{% block js_ready %}
{{ block.super }}
$("#build-list").bootstrapTable({});
{% endblock %}

View File

@ -294,6 +294,9 @@ class BuildAllocate(DetailView):
context['part'] = part
context['bom_items'] = bom_items
if str2bool(self.request.GET.get('edit', None)):
context['editing'] = True
return context

View File

@ -18,7 +18,7 @@
<hr>
<table clas='table table-striped table-condensed' id='part-table' data-toolbar='#button-toolbar'>
<table class='table table-striped table-condensed' id='part-table' data-toolbar='#button-toolbar'>
</table>
{% endblock %}