mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	Refactor SalesOrderAttachment forms
This commit is contained in:
		| @@ -259,6 +259,15 @@ class SOAttachmentList(generics.ListCreateAPIView, AttachmentMixin): | |||||||
|     ] |     ] | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class SOAttachmentDetail(generics.RetrieveUpdateAPIView, AttachmentMixin): | ||||||
|  |     """ | ||||||
|  |     Detail endpoint for SalesOrderAttachment | ||||||
|  |     """ | ||||||
|  |  | ||||||
|  |     queryset = SalesOrderAttachment.objects.all() | ||||||
|  |     serializer_class = SOAttachmentSerializer | ||||||
|  |  | ||||||
|  |  | ||||||
| class SOList(generics.ListCreateAPIView): | class SOList(generics.ListCreateAPIView): | ||||||
|     """ |     """ | ||||||
|     API endpoint for accessing a list of SalesOrder objects. |     API endpoint for accessing a list of SalesOrder objects. | ||||||
| @@ -579,6 +588,7 @@ order_api_urls = [ | |||||||
|     # API endpoints for sales ordesr |     # API endpoints for sales ordesr | ||||||
|     url(r'^so/', include([ |     url(r'^so/', include([ | ||||||
|         url(r'attachment/', include([ |         url(r'attachment/', include([ | ||||||
|  |             url(r'^(?P<pk>\d+)/$', SOAttachmentDetail.as_view(), name='api-so-attachment-detail'), | ||||||
|             url(r'^.*$', SOAttachmentList.as_view(), name='api-so-attachment-list'), |             url(r'^.*$', SOAttachmentList.as_view(), name='api-so-attachment-list'), | ||||||
|         ])), |         ])), | ||||||
|  |  | ||||||
|   | |||||||
| @@ -23,7 +23,7 @@ | |||||||
|  |  | ||||||
| enableDragAndDrop( | enableDragAndDrop( | ||||||
|     '#attachment-dropzone', |     '#attachment-dropzone', | ||||||
|     "{% url 'so-attachment-create' %}", |     '{% url "api-so-attachment-list" %}', | ||||||
|     { |     { | ||||||
|         data: { |         data: { | ||||||
|             order: {{ order.id }}, |             order: {{ order.id }}, | ||||||
| @@ -36,20 +36,36 @@ enableDragAndDrop( | |||||||
| ); | ); | ||||||
|  |  | ||||||
| $("#new-attachment").click(function() { | $("#new-attachment").click(function() { | ||||||
|     launchModalForm("{% url 'so-attachment-create' %}?order={{ order.id }}", |  | ||||||
|         { |     constructForm('{% url "api-so-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/sales-order/attachment/${button.attr('pk')}/edit/`; |     var pk = button.attr('pk'); | ||||||
|  |  | ||||||
|     launchModalForm(url, { |     var url = `/api/order/so/attachment/${pk}/`; | ||||||
|  |  | ||||||
|  |     constructForm(url, { | ||||||
|  |         fields: { | ||||||
|  |             attachment: {}, | ||||||
|  |             comment: {}, | ||||||
|  |         }, | ||||||
|         reload: true, |         reload: true, | ||||||
|  |         title: '{% trans "Edit Attachment" %}', | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -89,8 +89,6 @@ sales_order_urls = [ | |||||||
|     ])), |     ])), | ||||||
|  |  | ||||||
|     url(r'^attachment/', include([ |     url(r'^attachment/', include([ | ||||||
|         url(r'^new/', views.SalesOrderAttachmentCreate.as_view(), name='so-attachment-create'), |  | ||||||
|         url(r'^(?P<pk>\d+)/edit/', views.SalesOrderAttachmentEdit.as_view(), name='so-attachment-edit'), |  | ||||||
|         url(r'^(?P<pk>\d+)/delete/', views.SalesOrderAttachmentDelete.as_view(), name='so-attachment-delete'), |         url(r'^(?P<pk>\d+)/delete/', views.SalesOrderAttachmentDelete.as_view(), name='so-attachment-delete'), | ||||||
|     ])), |     ])), | ||||||
|  |  | ||||||
|   | |||||||
| @@ -96,66 +96,6 @@ class SalesOrderDetail(InvenTreeRoleMixin, DetailView): | |||||||
|     template_name = 'order/sales_order_detail.html' |     template_name = 'order/sales_order_detail.html' | ||||||
|  |  | ||||||
|  |  | ||||||
| class SalesOrderAttachmentCreate(AjaxCreateView): |  | ||||||
|     """ View for creating a new SalesOrderAttachment """ |  | ||||||
|  |  | ||||||
|     model = SalesOrderAttachment |  | ||||||
|     form_class = order_forms.EditSalesOrderAttachmentForm |  | ||||||
|     ajax_form_title = _('Add Sales Order Attachment') |  | ||||||
|  |  | ||||||
|     def save(self, form, **kwargs): |  | ||||||
|         """ |  | ||||||
|         Save the user that uploaded the attachment |  | ||||||
|         """ |  | ||||||
|  |  | ||||||
|         attachment = form.save(commit=False) |  | ||||||
|         attachment.user = self.request.user |  | ||||||
|         attachment.save() |  | ||||||
|  |  | ||||||
|     def get_data(self): |  | ||||||
|         return { |  | ||||||
|             'success': _('Added attachment') |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|     def get_initial(self): |  | ||||||
|         initials = super().get_initial().copy() |  | ||||||
|  |  | ||||||
|         try: |  | ||||||
|             initials['order'] = SalesOrder.objects.get(id=self.request.GET.get('order', None)) |  | ||||||
|         except (ValueError, SalesOrder.DoesNotExist): |  | ||||||
|             pass |  | ||||||
|  |  | ||||||
|         return initials |  | ||||||
|  |  | ||||||
|     def get_form(self): |  | ||||||
|         """ Hide the 'order' field """ |  | ||||||
|  |  | ||||||
|         form = super().get_form() |  | ||||||
|         form.fields['order'].widget = HiddenInput() |  | ||||||
|  |  | ||||||
|         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): | class PurchaseOrderAttachmentDelete(AjaxDeleteView): | ||||||
|     """ View for deleting a PurchaseOrderAttachment """ |     """ View for deleting a PurchaseOrderAttachment """ | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user