diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py
index 6b4e0706ee..1b7dda7b5d 100644
--- a/InvenTree/order/forms.py
+++ b/InvenTree/order/forms.py
@@ -15,7 +15,7 @@ from InvenTree.fields import RoundingDecimalFormField
from stock.models import StockLocation
from .models import PurchaseOrder, PurchaseOrderLineItem, PurchaseOrderAttachment
-from .models import SalesOrder, SalesOrderLineItem
+from .models import SalesOrder, SalesOrderLineItem, SalesOrderAttachment
class IssuePurchaseOrderForm(HelperForm):
@@ -103,6 +103,18 @@ class EditPurchaseOrderAttachmentForm(HelperForm):
]
+class EditSalesOrderAttachmentForm(HelperForm):
+ """ Form for editing a SalesOrderAttachment object """
+
+ class Meta:
+ model = SalesOrderAttachment
+ fields = [
+ 'order',
+ 'attachment',
+ 'comment'
+ ]
+
+
class EditPurchaseOrderLineItemForm(HelperForm):
""" Form for editing a PurchaseOrderLineItem object """
diff --git a/InvenTree/order/templates/order/po_delete.html b/InvenTree/order/templates/order/delete_attachment.html
similarity index 100%
rename from InvenTree/order/templates/order/po_delete.html
rename to InvenTree/order/templates/order/delete_attachment.html
diff --git a/InvenTree/order/templates/order/so_attachments.html b/InvenTree/order/templates/order/so_attachments.html
index 5d7a66e313..82248fd5eb 100644
--- a/InvenTree/order/templates/order/so_attachments.html
+++ b/InvenTree/order/templates/order/so_attachments.html
@@ -33,10 +33,10 @@
{{ attachment.comment }} |
-
@@ -52,7 +52,7 @@
{{ block.super }}
$("#new-attachment").click(function() {
- launchModalForm("{% url 'po-attachment-create' %}?order={{ order.id }}",
+ launchModalForm("{% url 'so-attachment-create' %}?order={{ order.id }}",
{
reload: true,
}
diff --git a/InvenTree/order/urls.py b/InvenTree/order/urls.py
index c3fdac407b..e56d0c9312 100644
--- a/InvenTree/order/urls.py
+++ b/InvenTree/order/urls.py
@@ -65,6 +65,13 @@ so_line_urls = [
url(r'^new/', views.SOLineItemCreate.as_view(), name='so-line-item-create'),
]
+sales_order_attachment_urls = [
+ url(r'^new/', views.SalesOrderAttachmentCreate.as_view(), name='so-attachment-create'),
+ url(r'^(?P\d+)/edit/', views.SalesOrderAttachmentEdit.as_view(), name='so-attachment-edit'),
+ url(r'^(?P\d+)/delete/', views.SalesOrderAttachmentDelete.as_view(), name='so-attachment-delete'),
+
+]
+
sales_order_detail_urls = [
url(r'^edit/', views.SalesOrderEdit.as_view(), name='so-edit'),
@@ -81,6 +88,8 @@ sales_order_urls = [
url(r'^line/', include(so_line_urls)),
+ url(r'^attachments/', include(sales_order_attachment_urls)),
+
# 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 d9ea9d01d1..a718c96cc4 100644
--- a/InvenTree/order/views.py
+++ b/InvenTree/order/views.py
@@ -129,6 +129,34 @@ class PurchaseOrderAttachmentCreate(AjaxCreateView):
return form
+class SalesOrderAttachmentCreate(AjaxCreateView):
+ """ View for creating a new SalesOrderAttachment """
+
+ model = SalesOrderAttachment
+ form_class = order_forms.EditSalesOrderAttachmentForm
+ ajax_form_title = _('Add Sales Order Attachment')
+
+ def get_data(self):
+ return {
+ 'success': _('Added attachment')
+ }
+
+ def get_initial(self):
+ initials = super().get_initial().copy()
+
+ initials['order'] = SalesOrder.objects.get(id=self.request.GET.get('order', None))
+
+ return initials
+
+ def get_form(self):
+ """ Hide the 'order' field """
+
+ form = super().get_form()
+ form.fields['order'].widget = HiddenInput()
+
+ return form
+
+
class PurchaseOrderAttachmentEdit(AjaxUpdateView):
""" View for editing a PurchaseOrderAttachment object """
@@ -150,12 +178,46 @@ class PurchaseOrderAttachmentEdit(AjaxUpdateView):
return form
+class SalesOrderAttachmentEdit(AjaxUpdateView):
+ """ View for editing a SalesOrderAttachment object """
+
+ model = SalesOrderAttachment
+ form_class = order_forms.EditSalesOrderAttachmentForm
+ ajax_form_title = _("Edit Attachment")
+
+ def get_data(self):
+ return {
+ 'success': _('Attachment updated')
+ }
+
+ def get_form(self):
+ form = super().get_form()
+
+ form.fields['order'].widget = HiddenInput()
+
+ return form
+
+
class PurchaseOrderAttachmentDelete(AjaxDeleteView):
""" View for deleting a PurchaseOrderAttachment """
model = PurchaseOrderAttachment
ajax_form_title = _("Delete Attachment")
- ajax_template_name = "order/po_delete.html"
+ 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):
|