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
1c1cc670f8
commit
080f9da9c8
@ -45,13 +45,34 @@ class CreateStockItemForm(HelperForm):
|
|||||||
class MoveStockItemForm(forms.ModelForm):
|
class MoveStockItemForm(forms.ModelForm):
|
||||||
""" Form for moving a StockItem to a new location """
|
""" 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)')
|
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:
|
class Meta:
|
||||||
model = StockItem
|
model = StockItem
|
||||||
|
|
||||||
fields = [
|
fields = [
|
||||||
'location',
|
'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'^track/?', views.StockTrackingIndex.as_view(), name='stock-tracking-list'),
|
||||||
|
|
||||||
|
url(r'^move/', views.StockItemMoveMultiple.as_view(), name='stock-item-move-multiple'),
|
||||||
|
|
||||||
# Individual stock items
|
# Individual stock items
|
||||||
url(r'^item/(?P<pk>\d+)/', include(stock_item_detail_urls)),
|
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 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.views.generic.edit import FormMixin
|
||||||
from django.views.generic import DetailView, ListView
|
from django.views.generic import DetailView, ListView
|
||||||
from django.forms.models import model_to_dict
|
from django.forms.models import model_to_dict
|
||||||
from django.forms import HiddenInput
|
from django.forms import HiddenInput
|
||||||
|
|
||||||
|
from InvenTree.views import AjaxView
|
||||||
from InvenTree.views import AjaxUpdateView, AjaxDeleteView, AjaxCreateView
|
from InvenTree.views import AjaxUpdateView, AjaxDeleteView, AjaxCreateView
|
||||||
from InvenTree.views import QRCodeView
|
from InvenTree.views import QRCodeView
|
||||||
|
|
||||||
@ -20,6 +22,7 @@ from .forms import CreateStockItemForm
|
|||||||
from .forms import EditStockItemForm
|
from .forms import EditStockItemForm
|
||||||
from .forms import MoveStockItemForm
|
from .forms import MoveStockItemForm
|
||||||
from .forms import StocktakeForm
|
from .forms import StocktakeForm
|
||||||
|
from .forms import MoveStockItemForm
|
||||||
|
|
||||||
|
|
||||||
class StockIndex(ListView):
|
class StockIndex(ListView):
|
||||||
@ -122,6 +125,36 @@ class StockItemQRCode(QRCodeView):
|
|||||||
return None
|
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):
|
class StockItemEdit(AjaxUpdateView):
|
||||||
"""
|
"""
|
||||||
View for editing details of a single StockItem
|
View for editing details of a single StockItem
|
||||||
|
Loading…
Reference in New Issue
Block a user