diff --git a/InvenTree/static/script/inventree/stock.js b/InvenTree/static/script/inventree/stock.js
index e18a1a6448..e38940ed40 100644
--- a/InvenTree/static/script/inventree/stock.js
+++ b/InvenTree/static/script/inventree/stock.js
@@ -540,6 +540,28 @@ function loadStockTable(table, options) {
linkButtonsToSelection(table, options.buttons);
}
+ function stockAdjustment(action) {
+ var items = $("#stock-table").bootstrapTable("getSelections");
+
+ var stock = [];
+
+ items.forEach(function(item) {
+ stock.push(item.pk);
+ });
+
+ launchModalForm("/stock/adjust/",
+ {
+ data: {
+ action: action,
+ stock: stock,
+ },
+ success: function() {
+ $("#stock-table").bootstrapTable('refresh');
+ },
+ }
+ );
+ }
+
// Automatically link button callbacks
$('#multi-item-stocktake').click(function() {
updateStockItems({
@@ -563,40 +585,7 @@ function loadStockTable(table, options) {
});
$("#multi-item-move").click(function() {
-
- var items = $('#stock-table').bootstrapTable('getSelections');
-
- var stock = [];
-
- items.forEach(function(item) {
- stock.push(item.pk);
- });
-
- launchModalForm("/stock/adjust/",
- {
- data: {
- action: 'move',
- stock: stock,
- },
- success: function() {
- $("#stock-table").bootstrapTable('refresh');
- },
- }
- );
-
- /*
-
- var items = $("#stock-table").bootstrapTable('getSelections');
-
- moveStockItems(items,
- {
- success: function() {
- $("#stock-table").bootstrapTable('refresh');
- }
- });
-
- return false;
- */
+ stockAdjustment('move');
});
}
diff --git a/InvenTree/stock/templates/stock/stock_adjust.html b/InvenTree/stock/templates/stock/stock_adjust.html
index d23317bd35..62e7412473 100644
--- a/InvenTree/stock/templates/stock/stock_adjust.html
+++ b/InvenTree/stock/templates/stock/stock_adjust.html
@@ -12,7 +12,7 @@
Stock Item |
Location |
- {{ stock_action }} |
+ {{ stock_action_title }} |
|
{% for item in stock_items %}
diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py
index 98dc09381c..eb744ee443 100644
--- a/InvenTree/stock/views.py
+++ b/InvenTree/stock/views.py
@@ -172,7 +172,13 @@ class StockAdjust(AjaxView, FormMixin):
items = None
for item in items:
- item.new_quantity = item.quantity
+
+ # Initialize quantity to zero for addition/removal
+ if self.stock_action in ['take', 'give']:
+ item.new_quantity = 0
+ # Initialize quantity at full amount for counting or moving
+ else:
+ item.new_quantity = item.quantity
return items
@@ -197,13 +203,6 @@ class StockAdjust(AjaxView, FormMixin):
items.append(stock_item)
return items
- def _get_form_kwargs(self):
-
- args = super().get_form_kwargs()
-
- #args['stock_items'] = self.stock_items
-
- return args
def get_context_data(self):
@@ -211,7 +210,9 @@ class StockAdjust(AjaxView, FormMixin):
context['stock_items'] = self.stock_items
- context['stock_action'] = self.stock_action
+ context['stock_action'] = self.stock_action
+
+ context['stock_action_title'] = self.stock_action.capitalize()
return context
@@ -220,8 +221,22 @@ class StockAdjust(AjaxView, FormMixin):
self.request = request
# Action
- self.stock_action = request.GET.get('action').lower()
+ self.stock_action = request.GET.get('action', '').lower()
+ # Pick a default action...
+ if self.stock_action not in ['move', 'count', 'take', 'give']:
+ self.stock_action = 'count'
+
+ # Choose the form title based on the action
+ titles = {
+ 'move': 'Move Stock',
+ 'count': 'Count Stock',
+ 'take': 'Remove Stock',
+ 'give': 'Add Stock'
+ }
+
+ self.ajax_form_title = titles[self.stock_action]
+
# Save list of items!
self.stock_items = self.get_GET_items()
@@ -229,13 +244,13 @@ class StockAdjust(AjaxView, FormMixin):
def post(self, request, *args, **kwargs):
- form = self.get_form()
-
self.request = request
# Update list of stock items
self.stock_items = self.get_POST_items()
+ form = self.get_form()
+
valid = form.is_valid()
for item in self.stock_items: