From 7575a39b7fd18f590da4f555867152500b2770e7 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 28 Aug 2019 21:46:26 +1000 Subject: [PATCH] Add form / view for serializing a stock item - Back end doesn't do anything yet --- InvenTree/stock/forms.py | 33 +++++++++++++++++++ InvenTree/stock/templates/stock/item.html | 9 +++++ .../stock/templates/stock/item_serialize.html | 6 ++++ InvenTree/stock/urls.py | 9 ++--- InvenTree/stock/views.py | 23 +++++++++++++ 5 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 InvenTree/stock/templates/stock/item_serialize.html diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index ecc71f3423..c3acfd436c 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -63,6 +63,39 @@ class CreateStockItemForm(HelperForm): self._clean_form() +class SerializeStockForm(forms.ModelForm): + """ Form for serializing a StockItem. """ + + destination = forms.ChoiceField(label='Destination', required=True, help_text='Destination for serialized stock (by default, will remain in current location)') + serial_numbers = forms.CharField(label='Serial numbers', required=True, help_text='Unique serial numbers') + note = forms.CharField(label='Notes', required=False, help_text='Add transaction note') + + def get_location_choices(self): + locs = StockLocation.objects.all() + + choices = [(None, '---------')] + + for loc in locs: + choices.append((loc.pk, loc.pathstring + ' - ' + loc.description)) + + return choices + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.fields['destination'].choices = self.get_location_choices() + + class Meta: + model = StockItem + + fields = [ + 'quantity', + 'serial_numbers', + 'destination', + 'note', + ] + + class AdjustStockForm(forms.ModelForm): """ Form for performing simple stock adjustments. diff --git a/InvenTree/stock/templates/stock/item.html b/InvenTree/stock/templates/stock/item.html index 2d59c9f84e..1e7e44046c 100644 --- a/InvenTree/stock/templates/stock/item.html +++ b/InvenTree/stock/templates/stock/item.html @@ -167,6 +167,15 @@ ); }); + $("#stock-serialize").click(function() { + launchModalForm( + "{% url 'stock-item-serialize' item.id %}", + { + reload: true, + } + ); + }); + $("#stock-duplicate").click(function() { launchModalForm( "{% url 'stock-item-create' %}", diff --git a/InvenTree/stock/templates/stock/item_serialize.html b/InvenTree/stock/templates/stock/item_serialize.html new file mode 100644 index 0000000000..bb0054cca2 --- /dev/null +++ b/InvenTree/stock/templates/stock/item_serialize.html @@ -0,0 +1,6 @@ +{% extends "modal_form.html" %} + +{% block pre_form_content %} +Create serialized items from this stock item.
+Select quantity to serialize, and unique serial numbers. +{% endblock %} \ No newline at end of file diff --git a/InvenTree/stock/urls.py b/InvenTree/stock/urls.py index 9e17d568cf..76fbaae669 100644 --- a/InvenTree/stock/urls.py +++ b/InvenTree/stock/urls.py @@ -17,11 +17,12 @@ stock_location_detail_urls = [ ] stock_item_detail_urls = [ - url(r'^edit/?', views.StockItemEdit.as_view(), name='stock-item-edit'), - 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'^edit/', views.StockItemEdit.as_view(), name='stock-item-edit'), + url(r'^serialize/', views.StockItemSerialize.as_view(), name='stock-item-serialize'), + 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'^add_tracking/?', views.StockItemTrackingCreate.as_view(), name='stock-tracking-create'), + url(r'^add_tracking/', views.StockItemTrackingCreate.as_view(), name='stock-tracking-create'), url('^.*$', views.StockItemDetail.as_view(), name='stock-item-detail'), ] diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 4ad10d1ada..3c056dc73a 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -29,6 +29,7 @@ from .forms import CreateStockItemForm from .forms import EditStockItemForm from .forms import AdjustStockForm from .forms import TrackingEntryForm +from .forms import SerializeStockForm class StockIndex(ListView): @@ -461,6 +462,28 @@ class StockLocationCreate(AjaxCreateView): return initials +class StockItemSerialize(AjaxView, FormMixin): + """ View for manually serializing a StockItem """ + + ajax_template_name = 'stock/item_serialize.html' + ajax_form_title = 'Serialize Stock' + form_class = SerializeStockForm + + def get(self, request, *args, **kwargs): + + return super().get(request, *args, **kwargs) + + def post(self, request, *args, **kwargs): + + form = self.get_form() + + data = { + 'form_valid': False, + } + + return self.renderJsonResponse(request, form, data=data) + + class StockItemCreate(AjaxCreateView): """ View for creating a new StockItem