Add form / view for serializing a stock item

- Back end doesn't do anything yet
This commit is contained in:
Oliver Walters 2019-08-28 21:46:26 +10:00
parent 3b8f5872ac
commit 7575a39b7f
5 changed files with 76 additions and 4 deletions

View File

@ -63,6 +63,39 @@ class CreateStockItemForm(HelperForm):
self._clean_form() 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): class AdjustStockForm(forms.ModelForm):
""" Form for performing simple stock adjustments. """ Form for performing simple stock adjustments.

View File

@ -167,6 +167,15 @@
); );
}); });
$("#stock-serialize").click(function() {
launchModalForm(
"{% url 'stock-item-serialize' item.id %}",
{
reload: true,
}
);
});
$("#stock-duplicate").click(function() { $("#stock-duplicate").click(function() {
launchModalForm( launchModalForm(
"{% url 'stock-item-create' %}", "{% url 'stock-item-create' %}",

View File

@ -0,0 +1,6 @@
{% extends "modal_form.html" %}
{% block pre_form_content %}
Create serialized items from this stock item.<br>
Select quantity to serialize, and unique serial numbers.
{% endblock %}

View File

@ -17,11 +17,12 @@ 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'^delete/?', views.StockItemDelete.as_view(), name='stock-item-delete'), url(r'^serialize/', views.StockItemSerialize.as_view(), name='stock-item-serialize'),
url(r'^qr_code/?', views.StockItemQRCode.as_view(), name='stock-item-qr'), 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'), url('^.*$', views.StockItemDetail.as_view(), name='stock-item-detail'),
] ]

View File

@ -29,6 +29,7 @@ from .forms import CreateStockItemForm
from .forms import EditStockItemForm from .forms import EditStockItemForm
from .forms import AdjustStockForm from .forms import AdjustStockForm
from .forms import TrackingEntryForm from .forms import TrackingEntryForm
from .forms import SerializeStockForm
class StockIndex(ListView): class StockIndex(ListView):
@ -461,6 +462,28 @@ class StockLocationCreate(AjaxCreateView):
return initials 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): class StockItemCreate(AjaxCreateView):
""" """
View for creating a new StockItem View for creating a new StockItem