mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Display 'no stock available' warning
This commit is contained in:
parent
04420b7f6b
commit
001dacc14e
9
InvenTree/build/templates/build/create_build_item.html
Normal file
9
InvenTree/build/templates/build/create_build_item.html
Normal file
@ -0,0 +1,9 @@
|
||||
{% extends "modal_form.html" %}
|
||||
|
||||
{% block pre_form_content %}
|
||||
{% if no_stock %}
|
||||
<div class='alert alert-danger alert-block' role='alert'>
|
||||
No stock available for {{ part }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
@ -355,9 +355,25 @@ class BuildItemCreate(AjaxCreateView):
|
||||
|
||||
model = BuildItem
|
||||
form_class = forms.EditBuildItemForm
|
||||
ajax_template_name = 'modal_form.html'
|
||||
ajax_template_name = 'build/create_build_item.html'
|
||||
ajax_form_title = 'Allocate new Part'
|
||||
|
||||
part = None
|
||||
available_stock = None
|
||||
|
||||
def get_context_data(self):
|
||||
ctx = super(AjaxCreateView, self).get_context_data()
|
||||
|
||||
if self.part:
|
||||
ctx['part'] = self.part
|
||||
|
||||
if self.available_stock:
|
||||
ctx['stock'] = self.available_stock
|
||||
else:
|
||||
ctx['no_stock'] = True
|
||||
|
||||
return ctx
|
||||
|
||||
def get_form(self):
|
||||
""" Create Form for making / editing new Part object """
|
||||
|
||||
@ -375,7 +391,7 @@ class BuildItemCreate(AjaxCreateView):
|
||||
|
||||
if part_id:
|
||||
try:
|
||||
Part.objects.get(pk=part_id)
|
||||
self.part = Part.objects.get(pk=part_id)
|
||||
|
||||
query = form.fields['stock_item'].queryset
|
||||
|
||||
@ -399,6 +415,8 @@ class BuildItemCreate(AjaxCreateView):
|
||||
form.fields['stock_item'].queryset = query
|
||||
|
||||
stocks = query.all()
|
||||
self.available_stock = stocks
|
||||
|
||||
# If there is only one item selected, select it
|
||||
if len(stocks) == 1:
|
||||
form.fields['stock_item'].initial = stocks[0].id
|
||||
@ -408,6 +426,7 @@ class BuildItemCreate(AjaxCreateView):
|
||||
pass
|
||||
|
||||
except Part.DoesNotExist:
|
||||
self.part = None
|
||||
pass
|
||||
|
||||
return form
|
||||
|
@ -56,7 +56,7 @@ function loadAllocationTable(table, part_id, part, url, required, button) {
|
||||
launchModalForm(button.attr('url'), {
|
||||
success: function() {
|
||||
table.bootstrapTable('refresh');
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -5,13 +5,13 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if form.pre_form_warning %}
|
||||
<div class='alert alert-warning' role='alert' style='display: block;'>
|
||||
<div class='alert alert-warning alert-block' role='alert'>
|
||||
{{ form.pre_form_warning }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% block non_field_error %}
|
||||
{% if form.non_field_errors %}
|
||||
<div class='alert alert-danger' role='alert' style='display: block;'>
|
||||
<div class='alert alert-danger alert-block' role='alert'>
|
||||
<b>Error Submitting Form:</b>
|
||||
{{ form.non_field_errors }}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user