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 0ce6c5f7d5
commit 0e3f74ef31
2 changed files with 37 additions and 0 deletions

View File

@ -550,6 +550,24 @@ 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/move/",
{
data: {
stock: stock,
},
}
);
/*
var items = $("#stock-table").bootstrapTable('getSelections');
moveStockItems(items,
@ -560,6 +578,7 @@ function loadStockTable(table, options) {
});
return false;
*/
});
}

View File

@ -132,9 +132,27 @@ class StockItemMoveMultiple(AjaxView, FormMixin):
ajax_form_title = 'Move Stock'
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):
item_list = request.GET.getlist('stock[]')
items = self.get_items(item_list)
print(items)
return self.renderJsonResponse(request, self.form_class())
def post(self, request, *args, **kwargs):