mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Refactor PurchaseOrderAttachment views
This commit is contained in:
parent
b946aedb5c
commit
60d599b476
@ -554,12 +554,22 @@ class POAttachmentList(generics.ListCreateAPIView, AttachmentMixin):
|
|||||||
serializer_class = POAttachmentSerializer
|
serializer_class = POAttachmentSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class POAttachmentDetail(generics.RetrieveUpdateDestroyAPIView, AttachmentMixin):
|
||||||
|
"""
|
||||||
|
Detail endpoint for a PurchaseOrderAttachment
|
||||||
|
"""
|
||||||
|
|
||||||
|
queryset = PurchaseOrderAttachment.objects.all()
|
||||||
|
serializer_class = POAttachmentSerializer
|
||||||
|
|
||||||
|
|
||||||
order_api_urls = [
|
order_api_urls = [
|
||||||
# API endpoints for purchase orders
|
# API endpoints for purchase orders
|
||||||
url(r'^po/(?P<pk>\d+)/$', PODetail.as_view(), name='api-po-detail'),
|
|
||||||
url(r'po/attachment/', include([
|
url(r'po/attachment/', include([
|
||||||
|
url(r'^(?P<pk>\d+)/$', POAttachmentDetail.as_view(), name='api-po-attachment-detail'),
|
||||||
url(r'^.*$', POAttachmentList.as_view(), name='api-po-attachment-list'),
|
url(r'^.*$', POAttachmentList.as_view(), name='api-po-attachment-list'),
|
||||||
])),
|
])),
|
||||||
|
url(r'^po/(?P<pk>\d+)/$', PODetail.as_view(), name='api-po-detail'),
|
||||||
url(r'^po/.*$', POList.as_view(), name='api-po-list'),
|
url(r'^po/.*$', POList.as_view(), name='api-po-list'),
|
||||||
|
|
||||||
# API endpoints for purchase order line items
|
# API endpoints for purchase order line items
|
||||||
@ -568,12 +578,11 @@ order_api_urls = [
|
|||||||
|
|
||||||
# API endpoints for sales ordesr
|
# API endpoints for sales ordesr
|
||||||
url(r'^so/', include([
|
url(r'^so/', include([
|
||||||
url(r'^(?P<pk>\d+)/$', SODetail.as_view(), name='api-so-detail'),
|
|
||||||
url(r'attachment/', include([
|
url(r'attachment/', include([
|
||||||
url(r'^.*$', SOAttachmentList.as_view(), name='api-so-attachment-list'),
|
url(r'^.*$', SOAttachmentList.as_view(), name='api-so-attachment-list'),
|
||||||
])),
|
])),
|
||||||
|
|
||||||
# List all sales orders
|
url(r'^(?P<pk>\d+)/$', SODetail.as_view(), name='api-so-detail'),
|
||||||
url(r'^.*$', SOList.as_view(), name='api-so-list'),
|
url(r'^.*$', SOList.as_view(), name='api-so-list'),
|
||||||
])),
|
])),
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
enableDragAndDrop(
|
enableDragAndDrop(
|
||||||
'#attachment-dropzone',
|
'#attachment-dropzone',
|
||||||
"{% url 'po-attachment-create' %}",
|
'{% url "api-po-attachment-list" %}',
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
order: {{ order.id }},
|
order: {{ order.id }},
|
||||||
@ -35,20 +35,36 @@ enableDragAndDrop(
|
|||||||
);
|
);
|
||||||
|
|
||||||
$("#new-attachment").click(function() {
|
$("#new-attachment").click(function() {
|
||||||
launchModalForm("{% url 'po-attachment-create' %}?order={{ order.id }}",
|
|
||||||
{
|
constructForm('{% url "api-po-attachment-list" %}', {
|
||||||
reload: true,
|
method: 'POST',
|
||||||
}
|
fields: {
|
||||||
);
|
attachment: {},
|
||||||
|
comment: {},
|
||||||
|
order: {
|
||||||
|
value: {{ order.pk }},
|
||||||
|
hidden: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
reload: true,
|
||||||
|
title: '{% trans "Add Attachment" %}',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#attachment-table").on('click', '.attachment-edit-button', function() {
|
$("#attachment-table").on('click', '.attachment-edit-button', function() {
|
||||||
var button = $(this);
|
var button = $(this);
|
||||||
|
|
||||||
var url = `/order/purchase-order/attachment/${button.attr('pk')}/edit/`;
|
var pk = button.attr('pk');
|
||||||
|
|
||||||
launchModalForm(url, {
|
var url = `/api/order/po/attachment/${pk}/`;
|
||||||
|
|
||||||
|
constructForm(url, {
|
||||||
|
fields: {
|
||||||
|
attachment: {},
|
||||||
|
comment: {},
|
||||||
|
},
|
||||||
reload: true,
|
reload: true,
|
||||||
|
title: '{% trans "Edit Attachment" %}',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -46,8 +46,6 @@ purchase_order_urls = [
|
|||||||
])),
|
])),
|
||||||
|
|
||||||
url(r'^attachment/', include([
|
url(r'^attachment/', include([
|
||||||
url(r'^new/', views.PurchaseOrderAttachmentCreate.as_view(), name='po-attachment-create'),
|
|
||||||
url(r'^(?P<pk>\d+)/edit/', views.PurchaseOrderAttachmentEdit.as_view(), name='po-attachment-edit'),
|
|
||||||
url(r'^(?P<pk>\d+)/delete/', views.PurchaseOrderAttachmentDelete.as_view(), name='po-attachment-delete'),
|
url(r'^(?P<pk>\d+)/delete/', views.PurchaseOrderAttachmentDelete.as_view(), name='po-attachment-delete'),
|
||||||
])),
|
])),
|
||||||
|
|
||||||
|
@ -96,58 +96,6 @@ class SalesOrderDetail(InvenTreeRoleMixin, DetailView):
|
|||||||
template_name = 'order/sales_order_detail.html'
|
template_name = 'order/sales_order_detail.html'
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrderAttachmentCreate(AjaxCreateView):
|
|
||||||
"""
|
|
||||||
View for creating a new PurchaseOrderAttachment
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = PurchaseOrderAttachment
|
|
||||||
form_class = order_forms.EditPurchaseOrderAttachmentForm
|
|
||||||
ajax_form_title = _("Add Purchase Order Attachment")
|
|
||||||
ajax_template_name = "modal_form.html"
|
|
||||||
|
|
||||||
def save(self, form, **kwargs):
|
|
||||||
|
|
||||||
attachment = form.save(commit=False)
|
|
||||||
attachment.user = self.request.user
|
|
||||||
attachment.save()
|
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
try:
|
|
||||||
initials["order"] = PurchaseOrder.objects.get(id=self.request.GET.get('order', -1))
|
|
||||||
except (ValueError, PurchaseOrder.DoesNotExist):
|
|
||||||
pass
|
|
||||||
|
|
||||||
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 SalesOrderAttachmentCreate(AjaxCreateView):
|
class SalesOrderAttachmentCreate(AjaxCreateView):
|
||||||
""" View for creating a new SalesOrderAttachment """
|
""" View for creating a new SalesOrderAttachment """
|
||||||
|
|
||||||
@ -188,27 +136,6 @@ class SalesOrderAttachmentCreate(AjaxCreateView):
|
|||||||
return form
|
return form
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrderAttachmentEdit(AjaxUpdateView):
|
|
||||||
""" View for editing a PurchaseOrderAttachment object """
|
|
||||||
|
|
||||||
model = PurchaseOrderAttachment
|
|
||||||
form_class = order_forms.EditPurchaseOrderAttachmentForm
|
|
||||||
ajax_form_title = _("Edit Attachment")
|
|
||||||
|
|
||||||
def get_data(self):
|
|
||||||
return {
|
|
||||||
'success': _('Attachment updated')
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_form(self):
|
|
||||||
form = super(AjaxUpdateView, self).get_form()
|
|
||||||
|
|
||||||
# Hide the 'order' field
|
|
||||||
form.fields['order'].widget = HiddenInput()
|
|
||||||
|
|
||||||
return form
|
|
||||||
|
|
||||||
|
|
||||||
class SalesOrderAttachmentEdit(AjaxUpdateView):
|
class SalesOrderAttachmentEdit(AjaxUpdateView):
|
||||||
""" View for editing a SalesOrderAttachment object """
|
""" View for editing a SalesOrderAttachment object """
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user