mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Update stock_move form template
This commit is contained in:
parent
8214aef0db
commit
6a04c8cbd3
@ -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
|
||||
|
@ -1 +1,33 @@
|
||||
{% extends "modal_form.html" %}
|
||||
{% block pre_form_content %}
|
||||
{% endblock %}
|
||||
<form method="post" action='' class='js-modal-form' enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
|
||||
{% crispy form %}
|
||||
|
||||
{% block form_data %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
<hr>
|
||||
<table class='table table-condensed table-striped' id='stock-table'>
|
||||
<tr>
|
||||
<th>Item</th>
|
||||
<th>Location</th>
|
||||
<th>{{ stock_action }}</th>
|
||||
</tr>
|
||||
{% for item in stock_items %}
|
||||
<tr id='stock-row-{{ item.id }}'>
|
||||
<td>{% include "hover_image.html" with image=item.part.image %}
|
||||
{{ item.part.full_name }} <small><i>{{ item.part.description }}</i></small></td>
|
||||
<td>{{ item.location.pathstring }}</td>
|
||||
<td>
|
||||
<input class='form-control' min='0' max='{{ item.quantity }}' value='{{ item.quantity }}' type='number' name='stock-id-{{ item.id }}' id='stock-id-{{ item.id }}'/>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
</form>
|
@ -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())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user