From 6a04c8cbd3f29216a499d756c5d59b7bc43787de Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 1 Jun 2019 21:16:59 +1000 Subject: [PATCH] Update stock_move form template --- InvenTree/stock/forms.py | 29 ++-------------- .../stock/templates/stock/stock_move.html | 34 ++++++++++++++++++- InvenTree/stock/views.py | 20 ++++++++--- 3 files changed, 50 insertions(+), 33 deletions(-) diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index 5ee74e40e3..c6563f1786 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -73,34 +73,9 @@ class MoveMultipleStockItemsForm(forms.ModelForm): confirm = forms.BooleanField(required=False, initial=False, label='Confirm Stock Movement', help_text='Confirm movement of stock items') def __init__(self, *args, **kwargs): - stock_items = kwargs.pop('stock_items', []) + super().__init__(*args, **kwargs) - super(MoveStockItemForm, self).__init__(*args, **kwargs) - - self.fields['location'].choices = self.get_location_choices() - - for item in stock_items: - field = forms.IntegerField( - label= str(item.part), - required=True, - initial=item.quantity, - help_text='Quantity for ' + str(item)) - - extra = { - 'name': str(item.part), - 'location': str(item.location), - 'quantity': str(item.quantity), - } - - field.extra = extra - - self.fields['stock_item_{id}'.format(id=item.id)] = field - - def get_stock_fields(self): - for field_name in self.fields: - if field_name.startswith('stock_item_'): - print(field_name, self[field_name], self[field_name].extra) - yield self[field_name] + self.fields['location'].choices = self.get_location_choices() class Meta: model = StockItem diff --git a/InvenTree/stock/templates/stock/stock_move.html b/InvenTree/stock/templates/stock/stock_move.html index c7de8c74b2..7830f18b10 100644 --- a/InvenTree/stock/templates/stock/stock_move.html +++ b/InvenTree/stock/templates/stock/stock_move.html @@ -1 +1,33 @@ -{% extends "modal_form.html" %} \ No newline at end of file +{% block pre_form_content %} +{% endblock %} +
+ {% csrf_token %} + {% load crispy_forms_tags %} + + + {% crispy form %} + + {% block form_data %} + + {% endblock %} + +
+ + + + + + + {% for item in stock_items %} + + + + + + {% endfor %} +
ItemLocation{{ stock_action }}
{% include "hover_image.html" with image=item.part.image %} + {{ item.part.full_name }} {{ item.part.description }}{{ item.location.pathstring }} + +
+ +
\ No newline at end of file diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 44593f3c42..bdf75c0bd5 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -23,6 +23,7 @@ from .forms import EditStockItemForm from .forms import MoveStockItemForm from .forms import StocktakeForm from .forms import MoveStockItemForm +from .forms import MoveMultipleStockItemsForm class StockIndex(ListView): @@ -130,8 +131,8 @@ class StockItemMoveMultiple(AjaxView, FormMixin): ajax_template_name = 'stock/stock_move.html' ajax_form_title = 'Move Stock' - form_class = MoveStockItemForm - items = [] + form_class = MoveMultipleStockItemsForm + stock_items = [] def get_items(self, item_list): """ Return list of stock items. """ @@ -146,18 +147,27 @@ class StockItemMoveMultiple(AjaxView, FormMixin): return items - def get_form_kwargs(self): + def _get_form_kwargs(self): args = super().get_form_kwargs() - args['stock_items'] = self.get_items(self.items) + #args['stock_items'] = self.stock_items return args + def get_context_data(self): + + context = super().get_context_data() + + context['stock_items'] = self.stock_items + context['stock_action'] = 'Move' + + return context + def get(self, request, *args, **kwargs): # Save list of items! - self.items = request.GET.getlist('stock[]') + self.stock_items = self.get_items(request.GET.getlist('stock[]')) return self.renderJsonResponse(request, self.get_form())