mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor deletion of multiple manufacturer part objects
- issues multiple DELETE requests via the API
This commit is contained in:
parent
206d7bd96a
commit
9bd71c1184
@ -25,7 +25,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<div class='btn-group'>
|
<div class='btn-group'>
|
||||||
<div class="dropdown" style="float: right;">
|
<div class="dropdown" style="float: right;">
|
||||||
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">{% trans "Options" %}
|
<button class="btn btn-primary dropdown-toggle" id='table-options', type="button" data-toggle="dropdown">{% trans "Options" %}
|
||||||
<span class="caret"></span>
|
<span class="caret"></span>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
@ -59,7 +59,9 @@
|
|||||||
data: {
|
data: {
|
||||||
manufacturer: {{ company.id }},
|
manufacturer: {{ company.id }},
|
||||||
},
|
},
|
||||||
reload: true,
|
success: function() {
|
||||||
|
$("#part-table").bootstrapTable("refresh");
|
||||||
|
},
|
||||||
secondary: [
|
secondary: [
|
||||||
{
|
{
|
||||||
field: 'part',
|
field: 'part',
|
||||||
@ -88,22 +90,15 @@
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
linkButtonsToSelection($("#manufacturer-table"), ['#table-options']);
|
||||||
|
|
||||||
$("#multi-part-delete").click(function() {
|
$("#multi-part-delete").click(function() {
|
||||||
var selections = $("#part-table").bootstrapTable("getSelections");
|
var selections = $("#part-table").bootstrapTable("getSelections");
|
||||||
|
|
||||||
var parts = [];
|
deleteManufacturerParts(selections, {
|
||||||
|
onSuccess: function() {
|
||||||
selections.forEach(function(item) {
|
$("#part-table").bootstrapTable("refresh");
|
||||||
parts.push(item.pk);
|
}
|
||||||
});
|
|
||||||
|
|
||||||
var url = "{% url 'manufacturer-part-delete' %}"
|
|
||||||
|
|
||||||
launchModalForm(url, {
|
|
||||||
data: {
|
|
||||||
parts: parts,
|
|
||||||
},
|
|
||||||
reload: true,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -259,33 +259,3 @@ class ManufacturerPartViewTests(CompanyViewTestBase):
|
|||||||
|
|
||||||
# Check that the ManufacturerPart was created!
|
# Check that the ManufacturerPart was created!
|
||||||
self.assertEqual(n + 1, ManufacturerPart.objects.all().count())
|
self.assertEqual(n + 1, ManufacturerPart.objects.all().count())
|
||||||
|
|
||||||
def test_manufacturer_part_delete(self):
|
|
||||||
"""
|
|
||||||
Test the ManufacturerPartDelete view
|
|
||||||
"""
|
|
||||||
|
|
||||||
url = reverse('manufacturer-part-delete')
|
|
||||||
|
|
||||||
# Get form using 'part' argument
|
|
||||||
response = self.client.get(url, {'part': '2'}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# POST to delete manufacturer part
|
|
||||||
n = ManufacturerPart.objects.count()
|
|
||||||
m = SupplierPart.objects.count()
|
|
||||||
|
|
||||||
response = self.client.post(
|
|
||||||
url,
|
|
||||||
{
|
|
||||||
'manufacturer-part-2': 'manufacturer-part-2',
|
|
||||||
'confirm_delete': True
|
|
||||||
},
|
|
||||||
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
|
|
||||||
# Check that the ManufacturerPart was deleted
|
|
||||||
self.assertEqual(n - 1, ManufacturerPart.objects.count())
|
|
||||||
# Check that the SupplierParts were deleted
|
|
||||||
self.assertEqual(m - 2, SupplierPart.objects.count())
|
|
||||||
|
@ -123,8 +123,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Wait for *all* the requests to complete
|
// Wait for *all* the requests to complete
|
||||||
$.when.apply($, requests).then(function() {
|
$.when(requests).then(function() {
|
||||||
$('#bom-table').bootstrapTable('refresh');
|
location.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,17 +60,10 @@
|
|||||||
|
|
||||||
var selections = $("#manufacturer-table").bootstrapTable("getSelections");
|
var selections = $("#manufacturer-table").bootstrapTable("getSelections");
|
||||||
|
|
||||||
var parts = [];
|
deleteManufacturerParts(selections, {
|
||||||
|
onSuccess: function() {
|
||||||
selections.forEach(function(item) {
|
$("#manufacturer-table").bootstrapTable("refresh");
|
||||||
parts.push(item.pk);
|
}
|
||||||
});
|
|
||||||
|
|
||||||
launchModalForm("{% url 'manufacturer-part-delete' %}", {
|
|
||||||
data: {
|
|
||||||
parts: parts,
|
|
||||||
},
|
|
||||||
reload: true,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -80,7 +73,7 @@
|
|||||||
{
|
{
|
||||||
params: {
|
params: {
|
||||||
part: {{ part.id }},
|
part: {{ part.id }},
|
||||||
part_detail: false,
|
part_detail: true,
|
||||||
manufacturer_detail: true,
|
manufacturer_detail: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -170,6 +170,61 @@ function loadCompanyTable(table, url, options={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function deleteManufacturerParts(selections, options={}) {
|
||||||
|
|
||||||
|
if (selections.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var parts = [];
|
||||||
|
|
||||||
|
var text = `
|
||||||
|
<div class='alert alert-block alert-danger'>
|
||||||
|
<p>{% trans "The following manufacturer parts will be deleted" %}:</p>
|
||||||
|
<ul>`;
|
||||||
|
|
||||||
|
selections.forEach(function(item) {
|
||||||
|
parts.push(item.pk);
|
||||||
|
|
||||||
|
text += `
|
||||||
|
<li>
|
||||||
|
<p>${item.MPN} - ${item.part_detail.full_name}</p>
|
||||||
|
</li>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
text += `
|
||||||
|
</ul>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
showQuestionDialog(
|
||||||
|
'{% trans "Delete Manufacturer Parts" %}',
|
||||||
|
text,
|
||||||
|
{
|
||||||
|
accept_text: '{% trans "Delete" %}',
|
||||||
|
accept: function() {
|
||||||
|
|
||||||
|
// Delete each manufacturer part
|
||||||
|
var requests = [];
|
||||||
|
|
||||||
|
parts.forEach(function(pk) {
|
||||||
|
var url = `/api/company/part/manufacturer/${pk}`;
|
||||||
|
|
||||||
|
requests.push(inventreeDelete(url));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for all the requests to complete
|
||||||
|
$.when(requests).then(function() {
|
||||||
|
|
||||||
|
if (options.onSuccess) {
|
||||||
|
options.onSuccess();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function loadManufacturerPartTable(table, url, options) {
|
function loadManufacturerPartTable(table, url, options) {
|
||||||
/*
|
/*
|
||||||
* Load manufacturer part table
|
* Load manufacturer part table
|
||||||
|
@ -906,7 +906,7 @@ function loadStockTable(table, options) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
$.when.apply($, requests).then(function() {
|
$.when(requests).then(function() {
|
||||||
$("#stock-table").bootstrapTable('refresh');
|
$("#stock-table").bootstrapTable('refresh');
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user