mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Better error reporting for quantity
This commit is contained in:
parent
c228a4998c
commit
20963f83d9
@ -67,7 +67,7 @@ class MoveMultipleStockItemsForm(forms.ModelForm):
|
|||||||
|
|
||||||
return choices
|
return choices
|
||||||
|
|
||||||
location = forms.ChoiceField(label='Destination', required=True, help_text='Destination stock location')
|
destination = 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')
|
# 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')
|
confirm = forms.BooleanField(required=False, initial=False, label='Confirm Stock Movement', help_text='Confirm movement of stock items')
|
||||||
@ -75,13 +75,13 @@ class MoveMultipleStockItemsForm(forms.ModelForm):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.fields['location'].choices = self.get_location_choices()
|
self.fields['destination'].choices = self.get_location_choices()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = StockItem
|
model = StockItem
|
||||||
|
|
||||||
fields = [
|
fields = [
|
||||||
'location',
|
'destination',
|
||||||
'note',
|
'note',
|
||||||
# 'transaction',
|
# 'transaction',
|
||||||
'confirm',
|
'confirm',
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
<td>{{ item.location.pathstring }}</td>
|
<td>{{ item.location.pathstring }}</td>
|
||||||
<td>
|
<td>
|
||||||
<input class='numberinput' min='0' max='{{ item.quantity }}' value='{{ item.new_quantity }}' type='number' name='stock-id-{{ item.id }}' id='stock-id-{{ item.id }}'/>
|
<input class='numberinput' min='0' max='{{ item.quantity }}' value='{{ item.new_quantity }}' type='number' name='stock-id-{{ item.id }}' id='stock-id-{{ item.id }}'/>
|
||||||
|
{% if item.error %}
|
||||||
|
<br><span class='help-inline'>{{ item.error }}</span>
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td><button class='btn btn-default btn-remove' id='del-{{ item.id }}' title='Remove item' type='button'><span row='stock-row-{{ item.id }}' onclick='removeStockRow()' class='glyphicon glyphicon-small glyphicon-remove'></span></button></td>
|
<td><button class='btn btn-default btn-remove' id='del-{{ item.id }}' title='Remove item' type='button'><span row='stock-row-{{ item.id }}' onclick='removeStockRow()' class='glyphicon glyphicon-small glyphicon-remove'></span></button></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -10,6 +10,8 @@ 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 django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from InvenTree.views import AjaxView
|
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
|
||||||
@ -229,7 +231,17 @@ class StockItemMoveMultiple(AjaxView, FormMixin):
|
|||||||
try:
|
try:
|
||||||
q = int(item.new_quantity)
|
q = int(item.new_quantity)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
item.error = 'Must enter integer value'
|
item.error = _('Must enter integer value')
|
||||||
|
valid = False
|
||||||
|
continue
|
||||||
|
|
||||||
|
if q < 0:
|
||||||
|
item.error = _('Quantity must be positive')
|
||||||
|
valid = False
|
||||||
|
continue
|
||||||
|
|
||||||
|
if q > item.quantity:
|
||||||
|
item.error = _('Quantity must not exceed {x}'.format(x=item.quantity))
|
||||||
valid = False
|
valid = False
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -237,7 +249,7 @@ class StockItemMoveMultiple(AjaxView, FormMixin):
|
|||||||
|
|
||||||
if not confirmed:
|
if not confirmed:
|
||||||
valid = False
|
valid = False
|
||||||
form.errors['confirm'] = ['Confirm stock adjustment']
|
form.errors['confirm'] = [_('Confirm stock adjustment')]
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'form_valid': False,
|
'form_valid': False,
|
||||||
|
Loading…
Reference in New Issue
Block a user