Create a new attachment against a PurchaseOrder

This commit is contained in:
Oliver Walters 2020-03-22 18:41:41 +11:00
parent 56a6943438
commit 834f80698b
5 changed files with 75 additions and 10 deletions

View File

@ -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 """

View File

@ -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() {

View File

@ -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'),
]

View File

@ -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=<pk>
"""
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 """

View File

@ -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<pk>\d+)/edit/?', views.PartAttachmentEdit.as_view(), name='part-attachment-edit'),
url(r'^(?P<pk>\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<pk>\d+)/edit/', views.PartParameterTemplateEdit.as_view(), name='part-param-template-edit'),
url('^template/(?P<pk>\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<pk>\d+)/edit/', views.PartParameterTemplateEdit.as_view(), name='part-param-template-edit'),
url(r'^template/(?P<pk>\d+)/delete/', views.PartParameterTemplateDelete.as_view(), name='part-param-template-edit'),
url('^new/', views.PartParameterCreate.as_view(), name='part-param-create'),
url('^(?P<pk>\d+)/edit/', views.PartParameterEdit.as_view(), name='part-param-edit'),
url('^(?P<pk>\d+)/delete/', views.PartParameterDelete.as_view(), name='part-param-delete'),
url(r'^new/', views.PartParameterCreate.as_view(), name='part-param-create'),
url(r'^(?P<pk>\d+)/edit/', views.PartParameterEdit.as_view(), name='part-param-edit'),
url(r'^(?P<pk>\d+)/delete/', views.PartParameterDelete.as_view(), name='part-param-delete'),
]