2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 11:10:54 +00:00

Converting more forms to the API (#3181)

* Delete category via the API

* Delete StockLocation via the API

* Delete StockItem via the API

- Removes the final instance of AjaxDelete

* Remove URL path

* Add missing code
This commit is contained in:
Oliver
2022-06-11 21:53:26 +10:00
committed by GitHub
parent 63f1e58ca9
commit 090f4f4387
14 changed files with 100 additions and 249 deletions

View File

@ -581,12 +581,9 @@ $('#stock-add').click(function() {
});
$("#stock-delete").click(function () {
launchModalForm(
"{% url 'stock-item-delete' item.id %}",
{
redirect: "{% url 'part-detail' item.part.id %}"
}
);
deleteStockItem({{ item.pk }}, {
redirect: '{% url "part-detail" item.part.pk %}',
});
});
{% if item.part.can_convert %}
@ -599,7 +596,6 @@ $("#stock-convert").click(function() {
});
{% endif %}
{% if item.in_stock %}
$("#stock-assign-to-customer").click(function() {

View File

@ -1,15 +0,0 @@
{% extends "modal_delete_form.html" %}
{% load i18n %}
{% load inventree_extras %}
{% block pre_form_content %}
<div class='alert alert-danger alert-block'>
{% trans "Are you sure you want to delete this stock item?" %}
<br>
{% decimal item.quantity as qty %}
{% blocktrans with full_name=item.part.full_name %}This will remove <strong>{{qty}}</strong> units of <strong>{{full_name}}</strong> from stock.{% endblocktrans %}
</div>
{% endblock %}

View File

@ -291,14 +291,15 @@
});
$('#location-delete').click(function() {
launchModalForm("{% url 'stock-location-delete' location.id %}",
{
redirect: "{% url 'stock-index' %}"
});
return false;
});
{% if location %}
deleteStockLocation({{ location.pk }}, {
{% if location.parent %}
redirect: '{% url "stock-location-detail" location.parent.pk %}',
{% else %}
redirect: '{% url "stock-index" %}',
{% endif %}
});
});
function adjustLocationStock(action) {
inventreeGet(
@ -329,8 +330,6 @@
adjustLocationStock('move');
});
{% endif %}
$('#show-qr-code').click(function() {
launchModalForm("{% url 'stock-location-qr' location.id %}",
{

View File

@ -1,34 +0,0 @@
{% extends "modal_delete_form.html" %}
{% load i18n %}
{% load inventree_extras %}
{% block pre_form_content %}
<div class='alert alert-block alert-danger'>
{% trans "Are you sure you want to delete this stock location?" %}
</div>
{% if location.children.all|length > 0 %}
<div class='alert alert-block alert-warning'>
{% blocktrans with n=location.children.all|length %}This location contains {{ n }} child locations{% endblocktrans %}.<br>
{% if location.parent %}
{% blocktrans with location=location.parent.name %}If this location is deleted, these child locations will be moved to {{ location }}{% endblocktrans %}.
{% else %}
{% trans "If this location is deleted, these child locations will be moved to the top level stock location" %}.
{% endif %}
</div>
{% endif %}
{% if location.stock_items.all|length > 0 %}
<div class='alert alert-block alert-warning'>
{% blocktrans with n=location.stock_items.all|length %}This location contains {{ n }} stock items{% endblocktrans %}.<br>
{% if location.parent %}
{% blocktrans with location=location.parent.name %}If this location is deleted, these stock items will be moved to {{ location }}{% endblocktrans %}.
{% else %}
{% trans "If this location is deleted, these stock items will be moved to the top level stock location" %}.
{% endif %}
</div>
{% endif %}
{% endblock %}

View File

@ -7,7 +7,6 @@ from stock import views
location_urls = [
re_path(r'^(?P<pk>\d+)/', include([
re_path(r'^delete/?', views.StockLocationDelete.as_view(), name='stock-location-delete'),
re_path(r'^qr_code/?', views.StockLocationQRCode.as_view(), name='stock-location-qr'),
# Anything else - direct to the location detail view
@ -18,7 +17,6 @@ location_urls = [
stock_item_detail_urls = [
re_path(r'^convert/', views.StockItemConvert.as_view(), name='stock-item-convert'),
re_path(r'^delete/', views.StockItemDelete.as_view(), name='stock-item-delete'),
re_path(r'^qr_code/', views.StockItemQRCode.as_view(), name='stock-item-qr'),
# Anything else - direct to the item detail view

View File

@ -6,8 +6,7 @@ from django.utils.translation import gettext_lazy as _
from django.views.generic import DetailView, ListView
import common.settings
from InvenTree.views import (AjaxDeleteView, AjaxUpdateView,
InvenTreeRoleMixin, QRCodeView)
from InvenTree.views import AjaxUpdateView, InvenTreeRoleMixin, QRCodeView
from plugin.views import InvenTreePluginViewMixin
from . import forms as StockForms
@ -163,29 +162,3 @@ class StockItemConvert(AjaxUpdateView):
stock_item.convert_to_variant(variant, user=self.request.user)
return stock_item
class StockLocationDelete(AjaxDeleteView):
"""View to delete a StockLocation.
Presents a deletion confirmation form to the user
"""
model = StockLocation
success_url = '/stock'
ajax_template_name = 'stock/location_delete.html'
context_object_name = 'location'
ajax_form_title = _('Delete Stock Location')
class StockItemDelete(AjaxDeleteView):
"""View to delete a StockItem.
Presents a deletion confirmation form to the user
"""
model = StockItem
success_url = '/stock/'
ajax_template_name = 'stock/item_delete.html'
context_object_name = 'item'
ajax_form_title = _('Delete Stock Item')