Ability to delete multiple stock items

This commit is contained in:
Oliver Walters 2019-11-16 20:19:10 +11:00
parent 789515e39d
commit 2261973331
2 changed files with 40 additions and 6 deletions

View File

@ -310,6 +310,18 @@ function loadStockTable(table, options) {
},
});
});
$("#multi-item-delete").click(function() {
var selections = $("#stock-table").bootstrapTable("getSelections");
var stock = [];
selections.forEach(function(item) {
stock.push(item.pk);
});
stockAdjustment('delete');
});
}

View File

@ -256,6 +256,7 @@ class StockAdjust(AjaxView, FormMixin):
- Add items to stock
- Count items
- Move stock
- Delete stock items
"""
@ -361,15 +362,16 @@ class StockAdjust(AjaxView, FormMixin):
self.stock_action = request.GET.get('action', '').lower()
# Pick a default action...
if self.stock_action not in ['move', 'count', 'take', 'add']:
if self.stock_action not in ['move', 'count', 'take', 'add', 'delete']:
self.stock_action = 'count'
# Choose the form title based on the action
titles = {
'move': 'Move Stock',
'count': 'Count Stock',
'take': 'Remove Stock',
'add': 'Add Stock'
'move': _('Move Stock Items'),
'count': _('Count Stock Items'),
'take': _('Remove From Stock'),
'add': _('Add Stock Items'),
'delete': _('Delete Stock Items')
}
self.ajax_form_title = titles[self.stock_action]
@ -383,7 +385,7 @@ class StockAdjust(AjaxView, FormMixin):
self.request = request
self.stock_action = request.POST.get('stock_action', 'invalid').lower()
self.stock_action = request.POST.get('stock_action', 'invalid').strip().lower()
# Update list of stock items
self.stock_items = self.get_POST_items()
@ -468,6 +470,9 @@ class StockAdjust(AjaxView, FormMixin):
elif self.stock_action == 'count':
return self.do_count()
elif self.stock_action == 'delete':
return self.do_delete()
else:
return 'No action performed'
@ -547,6 +552,23 @@ class StockAdjust(AjaxView, FormMixin):
n=count,
dest=destination.pathstring))
def do_delete(self):
""" Delete multiple stock items """
count = 0
# note = self.request.POST['note']
for item in self.stock_items:
# TODO - In the future, StockItems should not be 'deleted'
# TODO - Instead, they should be marked as "inactive"
item.delete()
count += 1
return _("Deleted {n} stock items".format(n=count))
class StockItemEdit(AjaxUpdateView):
"""