From 4e23dbd0af20d350b9b48864901cc06ee0e53378 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 30 Jun 2021 12:54:38 +1000 Subject: [PATCH] Refactor delete views for SalesOrderAttachment and PurchaseOrderAttachment --- .../build/templates/build/attachments.html | 11 ------- InvenTree/build/views.py | 2 +- InvenTree/order/api.py | 2 +- .../order/templates/order/po_attachments.html | 7 ++-- .../order/templates/order/so_attachments.html | 7 ++-- InvenTree/order/urls.py | 8 ----- InvenTree/order/views.py | 32 ++----------------- 7 files changed, 14 insertions(+), 55 deletions(-) diff --git a/InvenTree/build/templates/build/attachments.html b/InvenTree/build/templates/build/attachments.html index 839c275a9b..728c02fca7 100644 --- a/InvenTree/build/templates/build/attachments.html +++ b/InvenTree/build/templates/build/attachments.html @@ -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({}); diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index a3fd4fbd34..16004dacc1 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -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 diff --git a/InvenTree/order/api.py b/InvenTree/order/api.py index a128130f39..748cd360d8 100644 --- a/InvenTree/order/api.py +++ b/InvenTree/order/api.py @@ -259,7 +259,7 @@ class SOAttachmentList(generics.ListCreateAPIView, AttachmentMixin): ] -class SOAttachmentDetail(generics.RetrieveUpdateAPIView, AttachmentMixin): +class SOAttachmentDetail(generics.RetrieveUpdateDestroyAPIView, AttachmentMixin): """ Detail endpoint for SalesOrderAttachment """ diff --git a/InvenTree/order/templates/order/po_attachments.html b/InvenTree/order/templates/order/po_attachments.html index 20d15ea90f..a6ea769aee 100644 --- a/InvenTree/order/templates/order/po_attachments.html +++ b/InvenTree/order/templates/order/po_attachments.html @@ -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, }); }); diff --git a/InvenTree/order/templates/order/so_attachments.html b/InvenTree/order/templates/order/so_attachments.html index 90ba49a0ea..6df93bbe45 100644 --- a/InvenTree/order/templates/order/so_attachments.html +++ b/InvenTree/order/templates/order/so_attachments.html @@ -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, }); }); diff --git a/InvenTree/order/urls.py b/InvenTree/order/urls.py index db76306b3c..3863d895c8 100644 --- a/InvenTree/order/urls.py +++ b/InvenTree/order/urls.py @@ -45,10 +45,6 @@ purchase_order_urls = [ ])), ])), - url(r'^attachment/', include([ - url(r'^(?P\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\d+)/delete/', views.SalesOrderAttachmentDelete.as_view(), name='so-attachment-delete'), - ])), - # Display detail view for a single SalesOrder url(r'^(?P\d+)/', include(sales_order_detail_urls)), diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index 9cf53ec51c..04bd0d3828 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -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 """