mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 05:26:45 +00:00
Update stock_move form template
This commit is contained in:
parent
8214aef0db
commit
6a04c8cbd3
@ -73,35 +73,10 @@ class MoveMultipleStockItemsForm(forms.ModelForm):
|
|||||||
confirm = forms.BooleanField(required=False, initial=False, label='Confirm Stock Movement', help_text='Confirm movement of stock items')
|
confirm = forms.BooleanField(required=False, initial=False, label='Confirm Stock Movement', help_text='Confirm movement of stock items')
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
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()
|
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]
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = StockItem
|
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 MoveStockItemForm
|
||||||
from .forms import StocktakeForm
|
from .forms import StocktakeForm
|
||||||
from .forms import MoveStockItemForm
|
from .forms import MoveStockItemForm
|
||||||
|
from .forms import MoveMultipleStockItemsForm
|
||||||
|
|
||||||
|
|
||||||
class StockIndex(ListView):
|
class StockIndex(ListView):
|
||||||
@ -130,8 +131,8 @@ class StockItemMoveMultiple(AjaxView, FormMixin):
|
|||||||
|
|
||||||
ajax_template_name = 'stock/stock_move.html'
|
ajax_template_name = 'stock/stock_move.html'
|
||||||
ajax_form_title = 'Move Stock'
|
ajax_form_title = 'Move Stock'
|
||||||
form_class = MoveStockItemForm
|
form_class = MoveMultipleStockItemsForm
|
||||||
items = []
|
stock_items = []
|
||||||
|
|
||||||
def get_items(self, item_list):
|
def get_items(self, item_list):
|
||||||
""" Return list of stock items. """
|
""" Return list of stock items. """
|
||||||
@ -146,18 +147,27 @@ class StockItemMoveMultiple(AjaxView, FormMixin):
|
|||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def _get_form_kwargs(self):
|
||||||
|
|
||||||
args = super().get_form_kwargs()
|
args = super().get_form_kwargs()
|
||||||
|
|
||||||
args['stock_items'] = self.get_items(self.items)
|
#args['stock_items'] = self.stock_items
|
||||||
|
|
||||||
return args
|
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):
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
||||||
# Save list of items!
|
# 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())
|
return self.renderJsonResponse(request, self.get_form())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user