mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +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);
|
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
|
// Automatically link button callbacks
|
||||||
$('#multi-item-stocktake').click(function() {
|
$('#multi-item-stocktake').click(function() {
|
||||||
updateStockItems({
|
updateStockItems({
|
||||||
@ -563,40 +585,7 @@ function loadStockTable(table, options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#multi-item-move").click(function() {
|
$("#multi-item-move").click(function() {
|
||||||
|
stockAdjustment('move');
|
||||||
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;
|
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Stock Item</th>
|
<th>Stock Item</th>
|
||||||
<th>Location</th>
|
<th>Location</th>
|
||||||
<th>{{ stock_action }}</th>
|
<th>{{ stock_action_title }}</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for item in stock_items %}
|
{% for item in stock_items %}
|
||||||
|
@ -172,7 +172,13 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
items = None
|
items = None
|
||||||
|
|
||||||
for item in items:
|
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
|
return items
|
||||||
|
|
||||||
@ -197,13 +203,6 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
items.append(stock_item)
|
items.append(stock_item)
|
||||||
|
|
||||||
return items
|
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):
|
def get_context_data(self):
|
||||||
|
|
||||||
@ -211,7 +210,9 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
|
|
||||||
context['stock_items'] = self.stock_items
|
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
|
return context
|
||||||
|
|
||||||
@ -220,8 +221,22 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
self.request = request
|
self.request = request
|
||||||
|
|
||||||
# Action
|
# 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!
|
# Save list of items!
|
||||||
self.stock_items = self.get_GET_items()
|
self.stock_items = self.get_GET_items()
|
||||||
|
|
||||||
@ -229,13 +244,13 @@ class StockAdjust(AjaxView, FormMixin):
|
|||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
|
|
||||||
form = self.get_form()
|
|
||||||
|
|
||||||
self.request = request
|
self.request = request
|
||||||
|
|
||||||
# Update list of stock items
|
# Update list of stock items
|
||||||
self.stock_items = self.get_POST_items()
|
self.stock_items = self.get_POST_items()
|
||||||
|
|
||||||
|
form = self.get_form()
|
||||||
|
|
||||||
valid = form.is_valid()
|
valid = form.is_valid()
|
||||||
|
|
||||||
for item in self.stock_items:
|
for item in self.stock_items:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user