From 2a4e9037857dd783b80f9700d53be0bd3ee17865 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 22 Apr 2020 22:36:55 +1000 Subject: [PATCH] Add button to delete a SalesOrderLineItem --- InvenTree/InvenTree/fields.py | 4 +++- InvenTree/order/models.py | 3 ++- .../templates/order/sales_order_detail.html | 17 ++++++++++------- .../templates/order/so_lineitem_delete.html | 5 +++++ InvenTree/order/urls.py | 3 ++- InvenTree/order/views.py | 12 ++++++++++++ 6 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 InvenTree/order/templates/order/so_lineitem_delete.html diff --git a/InvenTree/InvenTree/fields.py b/InvenTree/InvenTree/fields.py index 4d8ab9ef82..ba3648da30 100644 --- a/InvenTree/InvenTree/fields.py +++ b/InvenTree/InvenTree/fields.py @@ -69,5 +69,7 @@ class RoundingDecimalField(models.DecimalField): defaults = { 'form_class': RoundingDecimalFormField } + defaults.update(kwargs) - return super(RoundingDecimalField, self).formfield(**kwargs) + + return super().formfield(**kwargs) diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index 53ee8be502..e6b35e1921 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -463,9 +463,10 @@ class SalesOrderAllocation(models.Model): on_delete=models.CASCADE, related_name='sales_order_allocations', limit_choices_to={'part__salable': True}, + help_text=_('Select stock item to allocate') ) - quantity = RoundingDecimalField(max_digits=15, decimal_places=5, validators=[MinValueValidator(0)], default=1) + quantity = RoundingDecimalField(max_digits=15, decimal_places=5, validators=[MinValueValidator(0)], default=1, help_text=_('Enter stock allocation quantity')) def get_allocated(self): """ String representation of the allocated quantity """ diff --git a/InvenTree/order/templates/order/sales_order_detail.html b/InvenTree/order/templates/order/sales_order_detail.html index 8f0ae24441..801669c1d7 100644 --- a/InvenTree/order/templates/order/sales_order_detail.html +++ b/InvenTree/order/templates/order/sales_order_detail.html @@ -156,6 +156,8 @@ $("#so-lines-table").inventreeTable({ } html += makeIconButton('fa-edit', 'button-edit', pk, '{% trans "Edit line item" %}'); + html += makeIconButton('fa-trash-alt', 'button-delete', pk, '{% trans "Delete line item " %}'); + html += ``; return html; @@ -181,12 +183,17 @@ $("#so-lines-table").on('load-success.bs.table', function() { launchModalForm(`/order/sales-order/line/${pk}/edit/`, { success: reloadTable, }); - console.log("clicked!"); + }); + + table.find(".button-delete").click(function() { + var pk = $(this).attr('pk'); + + launchModalForm(`/order/sales-order/line/${pk}/delete/`, { + reload: true, + }); }); table.find(".button-add").click(function() { - console.log("add"); - var pk = $(this).attr('pk'); launchModalForm(`/order/sales-order/allocation/new/`, { @@ -199,13 +206,9 @@ $("#so-lines-table").on('load-success.bs.table', function() { }); table.find(".button-build").click(function() { - console.log("build"); - - var pk = $(this).attr('pk'); }); table.find(".button-buy").click(function() { - console.log("buy"); }); }); diff --git a/InvenTree/order/templates/order/so_lineitem_delete.html b/InvenTree/order/templates/order/so_lineitem_delete.html new file mode 100644 index 0000000000..3264fea625 --- /dev/null +++ b/InvenTree/order/templates/order/so_lineitem_delete.html @@ -0,0 +1,5 @@ +{% extends "modal_delete_form.html" %} + +{% block pre_form_content %} +Are you sure you wish to delete this line item? +{% endblock %} \ No newline at end of file diff --git a/InvenTree/order/urls.py b/InvenTree/order/urls.py index 5f816ddfb5..b61dd445aa 100644 --- a/InvenTree/order/urls.py +++ b/InvenTree/order/urls.py @@ -65,7 +65,8 @@ purchase_order_urls = [ so_line_urls = [ url(r'^new/', views.SOLineItemCreate.as_view(), name='so-line-item-create'), url(r'^(?P\d+)/', include([ - url(r'^edit/', views.SOLineItemEdit.as_view(), name='so-line-item-edit') + url(r'^edit/', views.SOLineItemEdit.as_view(), name='so-line-item-edit'), + url(r'^delete/', views.SOLineItemDelete.as_view(), name='so-line-item-delete'), ])), ] diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index d09f543989..549bf1f496 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -1163,6 +1163,18 @@ class POLineItemDelete(AjaxDeleteView): } +class SOLineItemDelete(AjaxDeleteView): + + model = SalesOrderLineItem + ajax_form_title = _("Delete Line Item") + ajax_template_name = "order/so_lineitem_delete.html" + + def get_data(self): + return { + 'danger': _('Deleted line item'), + } + + class SalesOrderAllocationCreate(AjaxCreateView): """ View for creating a new SalesOrderAllocation """