mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Simplifiy js and improve template / form
This commit is contained in:
parent
c7503b4f9f
commit
d1ff115f74
@ -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');
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
<tr>
|
||||
<th>Stock Item</th>
|
||||
<th>Location</th>
|
||||
<th>{{ stock_action }}</th>
|
||||
<th>{{ stock_action_title }}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
{% for item in stock_items %}
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user