Pass list of selected stock items to the view

This commit is contained in:
Oliver Walters 2019-05-29 22:23:45 +10:00
parent f4a052ee2b
commit 72dc75512b
2 changed files with 37 additions and 0 deletions

View File

@ -550,6 +550,24 @@ function loadStockTable(table, options) {
$("#multi-item-move").click(function() { $("#multi-item-move").click(function() {
var items = $('#stock-table').bootstrapTable('getSelections');
var stock = [];
items.forEach(function(item) {
stock.push(item.pk);
});
launchModalForm("/stock/move/",
{
data: {
stock: stock,
},
}
);
/*
var items = $("#stock-table").bootstrapTable('getSelections'); var items = $("#stock-table").bootstrapTable('getSelections');
moveStockItems(items, moveStockItems(items,
@ -560,6 +578,7 @@ function loadStockTable(table, options) {
}); });
return false; return false;
*/
}); });
} }

View File

@ -132,9 +132,27 @@ class StockItemMoveMultiple(AjaxView, FormMixin):
ajax_form_title = 'Move Stock' ajax_form_title = 'Move Stock'
form_class = MoveStockItemForm form_class = MoveStockItemForm
def get_items(self, item_list):
""" Return list of stock items. """
items = []
for pk in item_list:
try:
items.append(StockItem.objects.get(pk=pk))
except StockItem.DoesNotExist:
pass
return items
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
item_list = request.GET.getlist('stock[]')
items = self.get_items(item_list)
print(items)
return self.renderJsonResponse(request, self.form_class()) return self.renderJsonResponse(request, self.form_class())
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):