Form / view / etc for performing StockItem conversion

This commit is contained in:
Oliver Walters 2020-05-25 14:16:38 +10:00
parent 009adaf528
commit fdf57891fc
5 changed files with 69 additions and 0 deletions

View File

@ -63,6 +63,18 @@ class EditStockLocationForm(HelperForm):
] ]
class ConvertStockItemForm(HelperForm):
"""
Form for converting a StockItem to a variant of its current part.
"""
class Meta:
model = StockItem
fields = [
'part'
]
class CreateStockItemForm(HelperForm): class CreateStockItemForm(HelperForm):
""" Form for creating a new StockItem """ """ Form for creating a new StockItem """

View File

@ -93,6 +93,11 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
<span class='fas fa-copy'/> <span class='fas fa-copy'/>
</button> </button>
{% endif %} {% endif %}
{% if item.part.has_variants %}
<button type='button' class='btn btn-default' id='stock-convert' title="Convert stock to variant">
<span class='fas fa-screwdriver'/>
</button>
{% endif %}
{% if item.part.has_test_report_templates %} {% if item.part.has_test_report_templates %}
<button type='button' class='btn btn-default' id='stock-test-report' title='Generate test report'> <button type='button' class='btn btn-default' id='stock-test-report' title='Generate test report'>
<span class='fas fa-tasks'/> <span class='fas fa-tasks'/>
@ -324,6 +329,16 @@ function itemAdjust(action) {
); );
} }
{% if item.part.has_variants %}
$("#stock-convert").click(function() {
launchModalForm("{% url 'stock-item-convert' item.id %}",
{
reload: true,
}
);
});
{% endif %}
$("#stock-move").click(function() { $("#stock-move").click(function() {
itemAdjust("move"); itemAdjust("move");
}); });

View File

@ -0,0 +1,17 @@
{% extends "modal_form.html" %}
{% load i18n %}
{% block pre_form_content %}
<div class='alert alert-block alert-info'>
<b>{% trans "Convert Stock Item" %}</b><br>
{% trans "This stock item is current an instance of " %}<i>{{ item.part }}</i><br>
{% trans "It can be converted to one of the part variants listed below." %}
</div>
<div class='alert alert-block alert-warning'>
<b>{% trans "Warning" %}</b>
{% trans "This action cannot be easily undone" %}
</div>
{% endblock %}

View File

@ -18,6 +18,7 @@ stock_location_detail_urls = [
stock_item_detail_urls = [ stock_item_detail_urls = [
url(r'^edit/', views.StockItemEdit.as_view(), name='stock-item-edit'), url(r'^edit/', views.StockItemEdit.as_view(), name='stock-item-edit'),
url(r'^convert/', views.StockItemEdit.as_view(), name='stock-item-convert'),
url(r'^serialize/', views.StockItemSerialize.as_view(), name='stock-item-serialize'), url(r'^serialize/', views.StockItemSerialize.as_view(), name='stock-item-serialize'),
url(r'^delete/', views.StockItemDelete.as_view(), name='stock-item-delete'), url(r'^delete/', views.StockItemDelete.as_view(), name='stock-item-delete'),
url(r'^qr_code/', views.StockItemQRCode.as_view(), name='stock-item-qr'), url(r'^qr_code/', views.StockItemQRCode.as_view(), name='stock-item-qr'),

View File

@ -887,6 +887,30 @@ class StockItemEdit(AjaxUpdateView):
return form return form
class StockItemEdit(AjaxUpdateView):
"""
View for 'converting' a StockItem to a variant of its current part.
"""
model = StockItem
form_class = StockForms.ConvertStockItemForm
ajax_form_title = _('Convert Stock Item')
ajax_template_name = 'stock/stockitem_convert.html'
context_object_name = 'item'
def get_form(self):
"""
Filter the available parts.
"""
form = super().get_form()
item = self.get_object()
form.fields['part'].queryset = item.part.get_all_variants()
return form
class StockLocationCreate(AjaxCreateView): class StockLocationCreate(AjaxCreateView):
""" """
View for creating a new StockLocation View for creating a new StockLocation