From 6112be2df0478be4da3b900756922431859a4206 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 22 Apr 2020 23:21:54 +1000 Subject: [PATCH] Add forms for editing and deleting a SalesOrderAllocation item --- InvenTree/InvenTree/static/css/inventree.css | 6 +++ .../order/templates/order/order_base.html | 24 ++++++------ .../templates/order/sales_order_base.html | 4 +- .../templates/order/sales_order_detail.html | 37 +++++++++++++++++-- InvenTree/order/urls.py | 1 + InvenTree/order/views.py | 7 ++++ 6 files changed, 61 insertions(+), 18 deletions(-) diff --git a/InvenTree/InvenTree/static/css/inventree.css b/InvenTree/InvenTree/static/css/inventree.css index f95f81ec1e..784828969e 100644 --- a/InvenTree/InvenTree/static/css/inventree.css +++ b/InvenTree/InvenTree/static/css/inventree.css @@ -325,6 +325,12 @@ padding-bottom: 2px; } +.btn-large { + font-size: 150%; + align-content: center; + vertical-align: middle; +} + .badge { float: right; background-color: #777; diff --git a/InvenTree/order/templates/order/order_base.html b/InvenTree/order/templates/order/order_base.html index 64026f2c5f..3840457a5e 100644 --- a/InvenTree/order/templates/order/order_base.html +++ b/InvenTree/order/templates/order/order_base.html @@ -27,27 +27,27 @@ src="{% static 'img/blank_image.png' %}"

- - {% if order.status == OrderStatus.PENDING and order.lines.count > 0 %} - {% elif order.status == OrderStatus.PLACED %} - - {% endif %} {% if order.status == OrderStatus.PENDING or order.status == OrderStatus.PLACED %} - {% endif %}
diff --git a/InvenTree/order/templates/order/sales_order_base.html b/InvenTree/order/templates/order/sales_order_base.html index a3b38b1f90..7ada7751d0 100644 --- a/InvenTree/order/templates/order/sales_order_base.html +++ b/InvenTree/order/templates/order/sales_order_base.html @@ -34,8 +34,8 @@ src="{% static 'img/blank_image.png' %}"

{{ order.description }}

-
diff --git a/InvenTree/order/templates/order/sales_order_detail.html b/InvenTree/order/templates/order/sales_order_detail.html index 801669c1d7..272a99af4e 100644 --- a/InvenTree/order/templates/order/sales_order_detail.html +++ b/InvenTree/order/templates/order/sales_order_detail.html @@ -55,7 +55,11 @@ $("#so-lines-table").inventreeTable({ element.html(html); - $(`#allocation-table-${row.pk}`).bootstrapTable({ + var lineItem = row; + + var table = $(`#allocation-table-${row.pk}`); + + table.bootstrapTable({ data: row.allocations, showHeader: false, columns: [ @@ -64,7 +68,7 @@ $("#so-lines-table").inventreeTable({ field: 'allocated', title: 'Quantity', formatter: function(value, row, index, field) { - return renderLink(value, `/stock/item/${row.pk}/`); + return renderLink(value, `/stock/item/${row.item}/`); }, }, { @@ -78,11 +82,37 @@ $("#so-lines-table").inventreeTable({ field: 'buttons', title: 'Actions', formatter: function(value, row, index, field) { - return ''; + + var html = "
"; + var pk = row.pk; + + html += makeIconButton('fa-edit', 'button-allocation-edit', pk, '{% trans "Edit stock allocation" %}'); + html += makeIconButton('fa-trash-alt', 'button-allocation-delete', pk, '{% trans "Delete stock allocation" %}'); + + html += "
"; + + return html; }, }, ], }); + + table.find(".button-allocation-edit").click(function() { + + var pk = $(this).attr('pk'); + + launchModalForm(`/order/sales-order/allocation/${pk}/edit/`, { + success: reloadTable, + }); + }); + + table.find(".button-allocation-delete").click(function() { + var pk = $(this).attr('pk'); + + launchModalForm(`/order/sales-order/allocation/${pk}/delete/`, { + success: reloadTable, + }); + }); }, columns: [ { @@ -202,7 +232,6 @@ $("#so-lines-table").on('load-success.bs.table', function() { line: pk, }, }); - }); table.find(".button-build").click(function() { diff --git a/InvenTree/order/urls.py b/InvenTree/order/urls.py index b61dd445aa..f390c23f54 100644 --- a/InvenTree/order/urls.py +++ b/InvenTree/order/urls.py @@ -98,6 +98,7 @@ sales_order_urls = [ url(r'^new/', views.SalesOrderAllocationCreate.as_view(), name='so-allocation-create'), url(r'(?P\d+)/', include([ url(r'^edit/', views.SalesOrderAllocationEdit.as_view(), name='so-allocation-edit'), + url(r'^delete/', views.SalesOrderAllocationDelete.as_view(), name='so-allocation-delete'), ])), ])), diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index 549bf1f496..1b91f6e9b4 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -1248,6 +1248,7 @@ class SalesOrderAllocationCreate(AjaxCreateView): class SalesOrderAllocationEdit(AjaxUpdateView): model = SalesOrderAllocation + form_class = order_forms.EditSalesOrderAllocationForm ajax_form_title = _('Edit Allocation Quantity') def get_form(self): @@ -1258,3 +1259,9 @@ class SalesOrderAllocationEdit(AjaxUpdateView): form.fields.pop('line') return form + + +class SalesOrderAllocationDelete(AjaxDeleteView): + + model = SalesOrderAllocation + ajax_form_title = _("Remove allocation")