Refactor delete views for SalesOrderAttachment and PurchaseOrderAttachment

This commit is contained in:
Oliver 2021-06-30 12:54:38 +10:00
parent 4d8e88c779
commit 4e23dbd0af
7 changed files with 14 additions and 55 deletions

View File

@ -76,17 +76,6 @@ $("#attachment-table").on('click', '.attachment-delete-button', function() {
title: '{% trans "Delete Attachment" %}',
reload: true,
});
return;
var url = `/build/attachment/${pk}/delete/`;
launchModalForm(
url,
{
reload: true,
}
);
});
$("#attachment-table").inventreeTable({});

View File

@ -12,7 +12,7 @@ from django.forms import HiddenInput
from django.urls import reverse
from part.models import Part
from .models import Build, BuildItem, BuildOrderAttachment
from .models import Build, BuildItem
from . import forms
from stock.models import StockLocation, StockItem

View File

@ -259,7 +259,7 @@ class SOAttachmentList(generics.ListCreateAPIView, AttachmentMixin):
]
class SOAttachmentDetail(generics.RetrieveUpdateAPIView, AttachmentMixin):
class SOAttachmentDetail(generics.RetrieveUpdateDestroyAPIView, AttachmentMixin):
"""
Detail endpoint for SalesOrderAttachment
"""

View File

@ -71,9 +71,12 @@ $("#attachment-table").on('click', '.attachment-edit-button', function() {
$("#attachment-table").on('click', '.attachment-delete-button', function() {
var button = $(this);
var url = `/order/purchase-order/attachment/${button.attr('pk')}/delete/`;
var pk = button.attr('pk');
launchModalForm(url, {
constructForm(`/api/order/po/attachment/${pk}/`, {
method: 'DELETE',
confirmMessage: '{% trans "Confirm Delete Operation" %}',
title: '{% trans "Delete Attachment" %}',
reload: true,
});
});

View File

@ -72,9 +72,12 @@ $("#attachment-table").on('click', '.attachment-edit-button', function() {
$("#attachment-table").on('click', '.attachment-delete-button', function() {
var button = $(this);
var url = `/order/sales-order/attachment/${button.attr('pk')}/delete/`;
var pk = button.attr('pk');
launchModalForm(url, {
constructForm(`/api/order/so/attachment/${pk}/`, {
method: 'DELETE',
confirmMessage: '{% trans "Confirm Delete Operation" %}',
title: '{% trans "Delete Attachment" %}',
reload: true,
});
});

View File

@ -45,10 +45,6 @@ purchase_order_urls = [
])),
])),
url(r'^attachment/', include([
url(r'^(?P<pk>\d+)/delete/', views.PurchaseOrderAttachmentDelete.as_view(), name='po-attachment-delete'),
])),
# Display complete list of purchase orders
url(r'^.*$', views.PurchaseOrderIndex.as_view(), name='po-index'),
]
@ -88,10 +84,6 @@ sales_order_urls = [
])),
])),
url(r'^attachment/', include([
url(r'^(?P<pk>\d+)/delete/', views.SalesOrderAttachmentDelete.as_view(), name='so-attachment-delete'),
])),
# Display detail view for a single SalesOrder
url(r'^(?P<pk>\d+)/', include(sales_order_detail_urls)),

View File

@ -20,8 +20,8 @@ from django.forms import HiddenInput, IntegerField
import logging
from decimal import Decimal, InvalidOperation
from .models import PurchaseOrder, PurchaseOrderLineItem, PurchaseOrderAttachment
from .models import SalesOrder, SalesOrderLineItem, SalesOrderAttachment
from .models import PurchaseOrder, PurchaseOrderLineItem
from .models import SalesOrder, SalesOrderLineItem
from .models import SalesOrderAllocation
from .admin import POLineItemResource
from build.models import Build
@ -96,34 +96,6 @@ class SalesOrderDetail(InvenTreeRoleMixin, DetailView):
template_name = 'order/sales_order_detail.html'
class PurchaseOrderAttachmentDelete(AjaxDeleteView):
""" View for deleting a PurchaseOrderAttachment """
model = PurchaseOrderAttachment
ajax_form_title = _("Delete Attachment")
ajax_template_name = "order/delete_attachment.html"
context_object_name = "attachment"
def get_data(self):
return {
"danger": _("Deleted attachment")
}
class SalesOrderAttachmentDelete(AjaxDeleteView):
""" View for deleting a SalesOrderAttachment """
model = SalesOrderAttachment
ajax_form_title = _("Delete Attachment")
ajax_template_name = "order/delete_attachment.html"
context_object_name = "attachment"
def get_data(self):
return {
"danger": _("Deleted attachment")
}
class PurchaseOrderNotes(InvenTreeRoleMixin, UpdateView):
""" View for updating the 'notes' field of a PurchaseOrder """