mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-05 23:08:48 +00:00
Remove 'destination' field if we are not moving stock
- Allow different stock adjustment actions
This commit is contained in:
parent
d1ff115f74
commit
8dd9034563
@ -578,10 +578,7 @@ function loadStockTable(table, options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('#multi-item-add').click(function() {
|
$('#multi-item-add').click(function() {
|
||||||
updateStockItems({
|
stockAdjustment('add');
|
||||||
action: 'add',
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#multi-item-move").click(function() {
|
$("#multi-item-move").click(function() {
|
||||||
|
@ -21,7 +21,10 @@
|
|||||||
{{ item.part.full_name }} <small><i>{{ item.part.description }}</i></small></td>
|
{{ item.part.full_name }} <small><i>{{ item.part.description }}</i></small></td>
|
||||||
<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'
|
||||||
|
{% if stock_action == 'move' %} max='{{ item.quantity }}' {% endif %}
|
||||||
|
value='{{ item.new_quantity }}' type='number' name='stock-id-{{ item.id }}' id='stock-id-{{ item.id }}'/>
|
||||||
{% if item.error %}
|
{% if item.error %}
|
||||||
<br><span class='help-inline'>{{ item.error }}</span>
|
<br><span class='help-inline'>{{ item.error }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -174,7 +174,7 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
for item in items:
|
for item in items:
|
||||||
|
|
||||||
# Initialize quantity to zero for addition/removal
|
# Initialize quantity to zero for addition/removal
|
||||||
if self.stock_action in ['take', 'give']:
|
if self.stock_action in ['take', 'add']:
|
||||||
item.new_quantity = 0
|
item.new_quantity = 0
|
||||||
# Initialize quantity at full amount for counting or moving
|
# Initialize quantity at full amount for counting or moving
|
||||||
else:
|
else:
|
||||||
@ -216,6 +216,15 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
def get_form(self):
|
||||||
|
|
||||||
|
form = super().get_form()
|
||||||
|
|
||||||
|
if not self.stock_action == 'move':
|
||||||
|
form.fields.pop('destination')
|
||||||
|
|
||||||
|
return form
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
||||||
self.request = request
|
self.request = request
|
||||||
@ -224,7 +233,7 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
self.stock_action = request.GET.get('action', '').lower()
|
self.stock_action = request.GET.get('action', '').lower()
|
||||||
|
|
||||||
# Pick a default action...
|
# Pick a default action...
|
||||||
if self.stock_action not in ['move', 'count', 'take', 'give']:
|
if self.stock_action not in ['move', 'count', 'take', 'add']:
|
||||||
self.stock_action = 'count'
|
self.stock_action = 'count'
|
||||||
|
|
||||||
# Choose the form title based on the action
|
# Choose the form title based on the action
|
||||||
@ -232,7 +241,7 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
'move': 'Move Stock',
|
'move': 'Move Stock',
|
||||||
'count': 'Count Stock',
|
'count': 'Count Stock',
|
||||||
'take': 'Remove Stock',
|
'take': 'Remove Stock',
|
||||||
'give': 'Add Stock'
|
'add': 'Add Stock'
|
||||||
}
|
}
|
||||||
|
|
||||||
self.ajax_form_title = titles[self.stock_action]
|
self.ajax_form_title = titles[self.stock_action]
|
||||||
@ -246,6 +255,8 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
|
|
||||||
self.request = request
|
self.request = request
|
||||||
|
|
||||||
|
self.stock_action = request.POST.get('stock_action').lower()
|
||||||
|
|
||||||
# Update list of stock items
|
# Update list of stock items
|
||||||
self.stock_items = self.get_POST_items()
|
self.stock_items = self.get_POST_items()
|
||||||
|
|
||||||
@ -265,11 +276,13 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
item.error = _('Quantity must be positive')
|
item.error = _('Quantity must be positive')
|
||||||
valid = False
|
valid = False
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if item.new_quantity > item.quantity:
|
if self.stock_action in ['move']:
|
||||||
item.error = _('Quantity must not exceed {x}'.format(x=item.quantity))
|
|
||||||
valid = False
|
if item.new_quantity > item.quantity:
|
||||||
continue
|
item.error = _('Quantity must not exceed {x}'.format(x=item.quantity))
|
||||||
|
valid = False
|
||||||
|
continue
|
||||||
|
|
||||||
confirmed = str2bool(request.POST.get('confirm'))
|
confirmed = str2bool(request.POST.get('confirm'))
|
||||||
|
|
||||||
@ -281,26 +294,68 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
'form_valid': valid,
|
'form_valid': valid,
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stock_action = request.POST.get('stock_action').lower()
|
|
||||||
|
|
||||||
if valid:
|
if valid:
|
||||||
|
|
||||||
if self.stock_action == 'move':
|
data['success'] = self.do_action()
|
||||||
|
|
||||||
destination = None
|
|
||||||
|
|
||||||
try:
|
|
||||||
destination = StockLocation.objects.get(id=form['destination'].value())
|
|
||||||
except StockLocation.DoesNotExist:
|
|
||||||
pass
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if destination:
|
|
||||||
data['success'] = self.do_move(destination)
|
|
||||||
|
|
||||||
return self.renderJsonResponse(request, form, data=data)
|
return self.renderJsonResponse(request, form, data=data)
|
||||||
|
|
||||||
|
def do_action(self):
|
||||||
|
""" Perform stock adjustment action """
|
||||||
|
|
||||||
|
if self.stock_action == 'move':
|
||||||
|
destination = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
destination = StockLocation.objects.get(id=self.request.POST.get('destination'))
|
||||||
|
except StockLocation.DoesNotExist:
|
||||||
|
pass
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return self.do_move(destination)
|
||||||
|
|
||||||
|
elif self.stock_action == 'add':
|
||||||
|
return self.do_add()
|
||||||
|
|
||||||
|
elif self.stock_action == 'take':
|
||||||
|
return self.do_take()
|
||||||
|
|
||||||
|
elif self.stock_action == 'count':
|
||||||
|
return self.do_count()
|
||||||
|
|
||||||
|
else:
|
||||||
|
return 'No action performed'
|
||||||
|
|
||||||
|
def do_add(self):
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
note = self.request.POST['note']
|
||||||
|
|
||||||
|
for item in self.stock_items:
|
||||||
|
if item.new_quantity <= 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
return _("Added stock to {n} items".format(n=count))
|
||||||
|
|
||||||
|
def do_take(self):
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
note = self.request.POST['note']
|
||||||
|
|
||||||
|
for item in self.stock_items:
|
||||||
|
if item.new_quantity <= 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
return _("Removed stock from {n} items".format(n=count))
|
||||||
|
|
||||||
|
def do_count(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def do_move(self, destination):
|
def do_move(self, destination):
|
||||||
""" Perform actual stock movement """
|
""" Perform actual stock movement """
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user