mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 21:38:48 +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
|
model = BuildItem
|
||||||
form_class = forms.EditBuildItemForm
|
form_class = forms.EditBuildItemForm
|
||||||
ajax_template_name = 'modal_form.html'
|
ajax_template_name = 'build/create_build_item.html'
|
||||||
ajax_form_title = 'Allocate new Part'
|
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):
|
def get_form(self):
|
||||||
""" Create Form for making / editing new Part object """
|
""" Create Form for making / editing new Part object """
|
||||||
|
|
||||||
@ -375,7 +391,7 @@ class BuildItemCreate(AjaxCreateView):
|
|||||||
|
|
||||||
if part_id:
|
if part_id:
|
||||||
try:
|
try:
|
||||||
Part.objects.get(pk=part_id)
|
self.part = Part.objects.get(pk=part_id)
|
||||||
|
|
||||||
query = form.fields['stock_item'].queryset
|
query = form.fields['stock_item'].queryset
|
||||||
|
|
||||||
@ -399,6 +415,8 @@ class BuildItemCreate(AjaxCreateView):
|
|||||||
form.fields['stock_item'].queryset = query
|
form.fields['stock_item'].queryset = query
|
||||||
|
|
||||||
stocks = query.all()
|
stocks = query.all()
|
||||||
|
self.available_stock = stocks
|
||||||
|
|
||||||
# If there is only one item selected, select it
|
# If there is only one item selected, select it
|
||||||
if len(stocks) == 1:
|
if len(stocks) == 1:
|
||||||
form.fields['stock_item'].initial = stocks[0].id
|
form.fields['stock_item'].initial = stocks[0].id
|
||||||
@ -408,6 +426,7 @@ class BuildItemCreate(AjaxCreateView):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
except Part.DoesNotExist:
|
except Part.DoesNotExist:
|
||||||
|
self.part = None
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return form
|
return form
|
||||||
|
@ -56,7 +56,7 @@ function loadAllocationTable(table, part_id, part, url, required, button) {
|
|||||||
launchModalForm(button.attr('url'), {
|
launchModalForm(button.attr('url'), {
|
||||||
success: function() {
|
success: function() {
|
||||||
table.bootstrapTable('refresh');
|
table.bootstrapTable('refresh');
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -5,13 +5,13 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if form.pre_form_warning %}
|
{% 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 }}
|
{{ form.pre_form_warning }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% block non_field_error %}
|
{% block non_field_error %}
|
||||||
{% if form.non_field_errors %}
|
{% 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>
|
<b>Error Submitting Form:</b>
|
||||||
{{ form.non_field_errors }}
|
{{ form.non_field_errors }}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user