mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Beginning to move the stocktake forms server side
This commit is contained in:
parent
da4f68e5a5
commit
2b4cb4d3e0
@ -45,13 +45,34 @@ class CreateStockItemForm(HelperForm):
|
||||
class MoveStockItemForm(forms.ModelForm):
|
||||
""" Form for moving a StockItem to a new location """
|
||||
|
||||
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
|
||||
|
||||
location = forms.ChoiceField(label='Destination', required=True, help_text='Destination stock location')
|
||||
note = forms.CharField(label='Notes', required=True, help_text='Add note (required)')
|
||||
transaction = forms.BooleanField(required=False, initial=False, label='Create Transaction', help_text='Create a stock transaction for these parts')
|
||||
confirm = forms.BooleanField(required=False, initial=False, label='Confirm Stock Movement', help_text='Confirm movement of stock items')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(MoveStockItemForm, self).__init__(*args, **kwargs)
|
||||
|
||||
self.fields['location'].choices = self.get_location_choices()
|
||||
|
||||
class Meta:
|
||||
model = StockItem
|
||||
|
||||
fields = [
|
||||
'location',
|
||||
'note',
|
||||
'transaction',
|
||||
'confirm',
|
||||
]
|
||||
|
||||
|
||||
|
1
InvenTree/stock/templates/stock/stock_move.html
Normal file
1
InvenTree/stock/templates/stock/stock_move.html
Normal file
@ -0,0 +1 @@
|
||||
{% extends "modal_form.html" %}
|
@ -36,6 +36,8 @@ stock_urls = [
|
||||
|
||||
url(r'^track/?', views.StockTrackingIndex.as_view(), name='stock-tracking-list'),
|
||||
|
||||
url(r'^move/', views.StockItemMoveMultiple.as_view(), name='stock-item-move-multiple'),
|
||||
|
||||
# Individual stock items
|
||||
url(r'^item/(?P<pk>\d+)/', include(stock_item_detail_urls)),
|
||||
|
||||
|
@ -5,10 +5,12 @@ Django views for interacting with Stock app
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.views.generic.edit import FormMixin
|
||||
from django.views.generic import DetailView, ListView
|
||||
from django.forms.models import model_to_dict
|
||||
from django.forms import HiddenInput
|
||||
|
||||
from InvenTree.views import AjaxView
|
||||
from InvenTree.views import AjaxUpdateView, AjaxDeleteView, AjaxCreateView
|
||||
from InvenTree.views import QRCodeView
|
||||
|
||||
@ -20,6 +22,7 @@ from .forms import CreateStockItemForm
|
||||
from .forms import EditStockItemForm
|
||||
from .forms import MoveStockItemForm
|
||||
from .forms import StocktakeForm
|
||||
from .forms import MoveStockItemForm
|
||||
|
||||
|
||||
class StockIndex(ListView):
|
||||
@ -120,6 +123,36 @@ class StockItemQRCode(QRCodeView):
|
||||
return item.format_barcode()
|
||||
except StockItem.DoesNotExist:
|
||||
return None
|
||||
|
||||
|
||||
class StockItemMoveMultiple(AjaxView, FormMixin):
|
||||
""" Move multiple stock items """
|
||||
|
||||
ajax_template_name = 'stock/stock_move.html'
|
||||
ajax_form_title = 'Move Stock'
|
||||
form_class = MoveStockItemForm
|
||||
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
||||
return self.renderJsonResponse(request, self.form_class())
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
|
||||
form = self.get_form()
|
||||
|
||||
valid = form.is_valid()
|
||||
|
||||
print("Valid:", valid)
|
||||
|
||||
data = {
|
||||
'form_valid': False,
|
||||
}
|
||||
|
||||
#form.errors['note'] = ['hello world']
|
||||
|
||||
return self.renderJsonResponse(request, form, data=data)
|
||||
|
||||
|
||||
|
||||
class StockItemEdit(AjaxUpdateView):
|
||||
|
Loading…
Reference in New Issue
Block a user