mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
Add bulk delete for purchase order line items (#4452)
* add bulk delete for purchase order line items * bump API version * fix JS style * handle parts with no linked manufacturer part correctly * add unit test for purchase order line item bulk delete
This commit is contained in:
@ -914,6 +914,7 @@ function poLineItemFields(options={}) {
|
||||
// Returned prices are in increasing order of quantity
|
||||
if (response.length > 0) {
|
||||
var idx = 0;
|
||||
var index = 0;
|
||||
|
||||
for (var idx = 0; idx < response.length; idx++) {
|
||||
if (response[idx].quantity > quantity) {
|
||||
@ -2213,6 +2214,71 @@ function loadPurchaseOrderTable(table, options) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Delete the selected Purchase Order Line Items from the database
|
||||
*/
|
||||
function deletePurchaseOrderLineItems(items, options={}) {
|
||||
|
||||
function renderItem(item, opts={}) {
|
||||
|
||||
var part = item.part_detail;
|
||||
var thumb = thumbnailImage(item.part_detail.thumbnail || item.part_detail.image);
|
||||
var MPN = item.supplier_part_detail.manufacturer_part_detail ? item.supplier_part_detail.manufacturer_part_detail.MPN : '-';
|
||||
|
||||
var html = `
|
||||
<tr>
|
||||
<td>${thumb} ${part.full_name}</td>
|
||||
<td>${part.description}</td>
|
||||
<td>${item.supplier_part_detail.SKU}</td>
|
||||
<td>${MPN}</td>
|
||||
<td>${item.quantity}
|
||||
</tr>
|
||||
`;
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
var rows = '';
|
||||
var ids = [];
|
||||
|
||||
items.forEach(function(item) {
|
||||
rows += renderItem(item);
|
||||
ids.push(item.pk);
|
||||
});
|
||||
|
||||
var html = `
|
||||
<div class='alert alert-block alert-danger'>
|
||||
{% trans "All selected Line items will be deleted" %}
|
||||
</div>
|
||||
|
||||
<table class='table table-striped table-condensed'>
|
||||
<tr>
|
||||
<th>{% trans "Part" %}</th>
|
||||
<th>{% trans "Description" %}</th>
|
||||
<th>{% trans "SKU" %}</th>
|
||||
<th>{% trans "MPN" %}</th>
|
||||
<th>{% trans "Quantity" %}</th>
|
||||
</tr>
|
||||
${rows}
|
||||
</table>
|
||||
`;
|
||||
|
||||
constructForm('{% url "api-po-line-list" %}', {
|
||||
method: 'DELETE',
|
||||
multi_delete: true,
|
||||
title: '{% trans "Delete selected Line items?" %}',
|
||||
form_data: {
|
||||
items: ids,
|
||||
},
|
||||
preFormContent: html,
|
||||
onSuccess: function() {
|
||||
// Refresh the table once the line items are deleted
|
||||
$('#po-line-table').bootstrapTable('refresh');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a table displaying line items for a particular PurchasesOrder
|
||||
* @param {String} table - HTML ID tag e.g. '#table'
|
||||
@ -2305,6 +2371,13 @@ function loadPurchaseOrderLineItemTable(table, options={}) {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Callback for bulk deleting mutliple lines
|
||||
$('#po-lines-bulk-delete').off('click').on('click', function() {
|
||||
var rows = getTableData(' #po-line-table');
|
||||
|
||||
deletePurchaseOrderLineItems(rows);
|
||||
});
|
||||
}
|
||||
|
||||
if (options.allow_receive) {
|
||||
@ -2569,6 +2642,13 @@ function loadPurchaseOrderLineItemTable(table, options={}) {
|
||||
]
|
||||
});
|
||||
|
||||
linkButtonsToSelection(
|
||||
table,
|
||||
[
|
||||
'#multi-select-options',
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user