diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py index 97e0f0bdd9..fead5d0496 100644 --- a/InvenTree/order/forms.py +++ b/InvenTree/order/forms.py @@ -13,7 +13,7 @@ from mptt.fields import TreeNodeChoiceField from InvenTree.forms import HelperForm from stock.models import StockLocation -from .models import PurchaseOrder, PurchaseOrderLineItem +from .models import PurchaseOrder, PurchaseOrderLineItem, PurchaseOrderAttachment class IssuePurchaseOrderForm(HelperForm): @@ -74,6 +74,18 @@ class EditPurchaseOrderForm(HelperForm): ] +class EditPurchaseOrderAttachmentForm(HelperForm): + """ Form for editing a PurchaseOrderAttachment object """ + + class Meta: + model = PurchaseOrderAttachment + fields = [ + 'order', + 'attachment', + 'comment' + ] + + class EditPurchaseOrderLineItemForm(HelperForm): """ Form for editing a PurchaseOrderLineItem object """ diff --git a/InvenTree/order/templates/order/po_attachments.html b/InvenTree/order/templates/order/po_attachments.html index 2e2e696833..13dad066df 100644 --- a/InvenTree/order/templates/order/po_attachments.html +++ b/InvenTree/order/templates/order/po_attachments.html @@ -52,7 +52,11 @@ {{ block.super }} $("#new-attachment").click(function() { - + launchModalForm("{% url 'purchase-order-attachment-create' %}?order={{ order.id }}", + { + reload: true, + } + ); }); $("#attachment-table").on('click', '.attachment-edit-button', function() { diff --git a/InvenTree/order/urls.py b/InvenTree/order/urls.py index e663dacba8..8a6613b563 100644 --- a/InvenTree/order/urls.py +++ b/InvenTree/order/urls.py @@ -9,6 +9,10 @@ from django.conf.urls import url, include from . import views +purchase_order_attachment_urls = [ + url(r'^new/', views.PurchaseOrderAttachmentCreate.as_view(), name='purchase-order-attachment-create'), +] + purchase_order_detail_urls = [ url(r'^cancel/?', views.PurchaseOrderCancel.as_view(), name='purchase-order-cancel'), @@ -49,6 +53,8 @@ purchase_order_urls = [ url(r'^line/', include(po_line_urls)), + url(r'^attachments/', include(purchase_order_attachment_urls)), + # Display complete list of purchase orders url(r'^.*$', views.PurchaseOrderIndex.as_view(), name='purchase-order-index'), ] diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index 2b31740bd2..09866f91dc 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -15,7 +15,7 @@ from django.forms import HiddenInput import logging from decimal import Decimal, InvalidOperation -from .models import PurchaseOrder, PurchaseOrderLineItem +from .models import PurchaseOrder, PurchaseOrderLineItem, PurchaseOrderAttachment from .admin import POLineItemResource from build.models import Build from company.models import Company, SupplierPart @@ -70,6 +70,49 @@ class PurchaseOrderDetail(DetailView): return ctx +class PurchaseOrderAttachmentCreate(AjaxCreateView): + """ + View for creating a new PurchaseOrderAtt + """ + + model = PurchaseOrderAttachment + form_class = order_forms.EditPurchaseOrderAttachmentForm + ajax_form_title = _("Add Purchase Order Attachment") + ajax_template_name = "modal_form.html" + + def get_data(self): + return { + "success": _("Added attachment") + } + + def get_initial(self): + """ + Get initial data for creating a new PurchaseOrderAttachment object. + + - Client must request this form with a parent PurchaseOrder in midn. + - e.g. ?order= + """ + + initials = super(AjaxCreateView, self).get_initial() + + initials["order"] = PurchaseOrder.objects.get(id=self.request.GET.get('order', -1)) + + return initials + + def get_form(self): + """ + Create a form to upload a new PurchaseOrderAttachment + + - Hide the 'order' field + """ + + form = super(AjaxCreateView, self).get_form() + + form.fields['order'].widget = HiddenInput() + + return form + + class PurchaseOrderNotes(UpdateView): """ View for updating the 'notes' field of a PurchaseOrder """ diff --git a/InvenTree/part/urls.py b/InvenTree/part/urls.py index 36be170bcb..0d376f8e5b 100644 --- a/InvenTree/part/urls.py +++ b/InvenTree/part/urls.py @@ -13,20 +13,20 @@ from django.conf.urls import url, include from . import views part_attachment_urls = [ - url('^new/?', views.PartAttachmentCreate.as_view(), name='part-attachment-create'), + url(r'^new/?', views.PartAttachmentCreate.as_view(), name='part-attachment-create'), url(r'^(?P\d+)/edit/?', views.PartAttachmentEdit.as_view(), name='part-attachment-edit'), url(r'^(?P\d+)/delete/?', views.PartAttachmentDelete.as_view(), name='part-attachment-delete'), ] part_parameter_urls = [ - url('^template/new/', views.PartParameterTemplateCreate.as_view(), name='part-param-template-create'), - url('^template/(?P\d+)/edit/', views.PartParameterTemplateEdit.as_view(), name='part-param-template-edit'), - url('^template/(?P\d+)/delete/', views.PartParameterTemplateDelete.as_view(), name='part-param-template-edit'), + url(r'^template/new/', views.PartParameterTemplateCreate.as_view(), name='part-param-template-create'), + url(r'^template/(?P\d+)/edit/', views.PartParameterTemplateEdit.as_view(), name='part-param-template-edit'), + url(r'^template/(?P\d+)/delete/', views.PartParameterTemplateDelete.as_view(), name='part-param-template-edit'), - url('^new/', views.PartParameterCreate.as_view(), name='part-param-create'), - url('^(?P\d+)/edit/', views.PartParameterEdit.as_view(), name='part-param-edit'), - url('^(?P\d+)/delete/', views.PartParameterDelete.as_view(), name='part-param-delete'), + url(r'^new/', views.PartParameterCreate.as_view(), name='part-param-create'), + url(r'^(?P\d+)/edit/', views.PartParameterEdit.as_view(), name='part-param-edit'), + url(r'^(?P\d+)/delete/', views.PartParameterDelete.as_view(), name='part-param-delete'), ]