2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 04:55:44 +00:00

Delete part via API (#3135)

* Updates for the PartRelated model

- Deleting a part also deletes the relationships
- Add unique_together requirement
- Bug fixes
- Added unit tests

* Adds JS function to delete a part instance

* Remove legacy delete view

* JS linting
This commit is contained in:
Oliver
2022-06-06 11:42:22 +10:00
committed by GitHub
parent f38386b13c
commit fe8f111a63
8 changed files with 151 additions and 143 deletions

View File

@ -21,6 +21,7 @@
*/
/* exported
deletePart,
duplicateBom,
duplicatePart,
editCategory,
@ -395,6 +396,50 @@ function duplicatePart(pk, options={}) {
}
// Launch form to delete a part
function deletePart(pk, options={}) {
inventreeGet(`/api/part/${pk}/`, {}, {
success: function(part) {
if (part.active) {
showAlertDialog(
'{% trans "Active Part" %}',
'{% trans "Part cannot be deleted as it is currently active" %}',
{
alert_style: 'danger',
}
);
return;
}
var thumb = thumbnailImage(part.thumbnail || part.image);
var html = `
<div class='alert alert-block alert-danger'>
<p>${thumb} ${part.full_name} - <em>${part.description}</em></p>
{% trans "Deleting this part cannot be reversed" %}
<ul>
<li>{% trans "Any stock items for this part will be deleted" %}</li>
<li>{% trans "This part will be removed from any Bills of Material" %}</li>
<li>{% trans "All manufacturer and supplier information for this part will be deleted" %}</li>
</div>`;
constructForm(
`/api/part/${pk}/`,
{
method: 'DELETE',
title: '{% trans "Delete Part" %}',
preFormContent: html,
onSuccess: function(response) {
handleFormSuccess(response, options);
}
}
);
}
});
}
/* Toggle the 'starred' status of a part.
* Performs AJAX queries and updates the display on the button.
*