Add / edit / delete attachments for SalesOrder

This commit is contained in:
Oliver Walters 2020-04-21 09:42:11 +10:00
parent a06595c152
commit 19cd0707a2
5 changed files with 88 additions and 5 deletions

View File

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

View File

@ -33,10 +33,10 @@
<td>{{ attachment.comment }}</td>
<td>
<div class='btn-group' style='float: right;'>
<button type='button' class='btn btn-default btn-glyph attachment-edit-button' url="{% url 'po-attachment-edit' attachment.id %}" data-toggle='tooltip' title='{% trans "Edit attachment" %}'>
<button type='button' class='btn btn-default btn-glyph attachment-edit-button' url="{% url 'so-attachment-edit' attachment.id %}" data-toggle='tooltip' title='{% trans "Edit attachment" %}'>
<span class='glyphicon glyphicon-edit'/>
</button>
<button type='button' class='btn btn-default btn-glyph attachment-delete-button' url="{% url 'po-attachment-delete' attachment.id %}" data-toggle='tooltip' title='{% trans "Delete attachment" %}'>
<button type='button' class='btn btn-default btn-glyph attachment-delete-button' url="{% url 'so-attachment-delete' attachment.id %}" data-toggle='tooltip' title='{% trans "Delete attachment" %}'>
<span class='glyphicon glyphicon-trash'/>
</button>
</div>
@ -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,
}

View File

@ -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<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'),
]
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<pk>\d+)/', include(sales_order_detail_urls)),

View File

@ -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):