Launch order dialog from the 'Parts' table

This commit is contained in:
Oliver Walters 2019-06-11 23:55:20 +10:00
parent 0ca01fb0e7
commit 1cb6c67086
3 changed files with 34 additions and 1 deletions

View File

@ -194,8 +194,22 @@ class OrderParts(AjaxView):
for item in stock_items: for item in stock_items:
part_ids.add(item.part.id) part_ids.add(item.part.id)
print("Parts:", part_ids)
# User has passed a list of part ID values
if 'parts[]' in self.request.GET:
part_id_list = self.request.GET.getlist('parts[]')
print("Provided list of part:")
print(part_id_list)
parts = Part.objects.filter(
purchaseable=True,
id__in=part_id_list)
for part in parts:
part_ids.add(part.id)
print("Parts:", part_ids)
# Create the list of parts # Create the list of parts
for id in part_ids: for id in part_ids:

View File

@ -49,6 +49,7 @@
<div class='dropdown' style='float: right;'> <div class='dropdown' style='float: right;'>
<button id='part-options' class='btn btn-primary dropdown-toggle' type='button' data-toggle="dropdown">Options<span class='caret'></span></button> <button id='part-options' class='btn btn-primary dropdown-toggle' type='button' data-toggle="dropdown">Options<span class='caret'></span></button>
<ul class='dropdown-menu'> <ul class='dropdown-menu'>
<li><a href='#' id='multi-part-order' title='Order parts'>Order Parts</a></li>
<li><a href='#' id='multi-part-category' title='Set Part Category'>Set Category</a></li> <li><a href='#' id='multi-part-category' title='Set Part Category'>Set Category</a></li>
</ul> </ul>
</div> </div>

View File

@ -192,4 +192,22 @@ function loadPartTable(table, url, options={}) {
if (options.buttons) { if (options.buttons) {
linkButtonsToSelection($(table), options.buttons); linkButtonsToSelection($(table), options.buttons);
} }
/* Button callbacks for part table buttons */
$("#multi-part-order").click(function() {
var selections = $(table).bootstrapTable("getSelections");
var parts = [];
selections.forEach(function(item) {
parts.push(item.pk);
});
launchModalForm("/order/purchase-order/order-parts/", {
data: {
parts: parts,
},
});
});
} }