From 449e0c0af26a4e210ff03ca2a212091eeb734b9c Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 23 Aug 2021 00:17:45 +1000 Subject: [PATCH 1/2] Refactor button in first step of "order parts" wizard - "new supplier part" button was broken - Was linked to the old "launchModalForm" code - Now calls createSupplierPart --- InvenTree/templates/js/translated/order.js | 46 ++++++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js index 8a8f45103c..2381e3bd25 100644 --- a/InvenTree/templates/js/translated/order.js +++ b/InvenTree/templates/js/translated/order.js @@ -109,27 +109,47 @@ function newSupplierPartFromOrderWizard(e) { var part = $(src).attr('part'); - console.log('part: ' + part); - if (!part) { part = $(src).closest('button').attr('part'); console.log('parent: ' + part); } - launchModalForm("/supplier-part/new/", { - modal: '#modal-form-secondary', - data: { - part: part, - }, - success: function(response) { - /* A new supplier part has been created! */ + createSupplierPart({ + part: part, + onSuccess: function(response) { + + // TODO: 2021-08-23 - This whole form wizard needs to be refactored. + // In the future, use the API forms functionality to add the new item + // For now, this hack will have to do... - var dropdown = '#id_supplier_part_' + part; + var dropdown = `#id_supplier_part_${part}`; - var option = new Option(response.text, response.pk, true, true); + var pk = response.pk; - $('#modal-form').find(dropdown).append(option).trigger('change'); - }, + inventreeGet( + `/api/company/part/${pk}/`, + { + supplier_detail: true, + }, + { + success: function(response) { + var text = ''; + + if (response.supplier_detail) { + text += response.supplier_detail.name; + text += " | "; + } + + text += response.SKU; + + var option = new Option(text, pk, true, true); + + $('#modal-form').find(dropdown).append(option).trigger('change'); + } + } + ) + + } }); } From 174b7ba7f27faa942fd920cd2093c3f5a682cbb8 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 23 Aug 2021 00:28:36 +1000 Subject: [PATCH 2/2] Fix for "new purchase order" button --- InvenTree/templates/js/translated/order.js | 56 ++++++++++++++++------ 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js index 2381e3bd25..c6dd773373 100644 --- a/InvenTree/templates/js/translated/order.js +++ b/InvenTree/templates/js/translated/order.js @@ -78,7 +78,13 @@ function createPurchaseOrder(options={}) { } }, onSuccess: function(data) { - location.href = `/order/purchase-order/${data.pk}/`; + + if (options.onSuccess) { + options.onSuccess(data); + } else { + // Default action is to redirect browser to the new PO + location.href = `/order/purchase-order/${data.pk}/`; + } }, title: '{% trans "Create Purchase Order" %}', }); @@ -116,7 +122,7 @@ function newSupplierPartFromOrderWizard(e) { createSupplierPart({ part: part, - onSuccess: function(response) { + onSuccess: function(data) { // TODO: 2021-08-23 - This whole form wizard needs to be refactored. // In the future, use the API forms functionality to add the new item @@ -124,7 +130,7 @@ function newSupplierPartFromOrderWizard(e) { var dropdown = `#id_supplier_part_${part}`; - var pk = response.pk; + var pk = data.pk; inventreeGet( `/api/company/part/${pk}/`, @@ -165,21 +171,41 @@ function newPurchaseOrderFromOrderWizard(e) { var supplier = $(src).attr('supplierid'); - launchModalForm("/order/purchase-order/new/", { - modal: '#modal-form-secondary', - data: { - supplier: supplier, - }, - success: function(response) { - /* A new purchase order has been created! */ + createPurchaseOrder({ + supplier: supplier, + onSuccess: function(data) { - var dropdown = '#id-purchase-order-' + supplier; + // TODO: 2021-08-23 - The whole form wizard needs to be refactored + // In the future, the drop-down should be using a dynamic AJAX request + // to fill out the select2 options! - var option = new Option(response.text, response.pk, true, true); + var pk = data.pk; - $('#modal-form').find(dropdown).append(option).trigger('change'); - }, - }); + inventreeGet( + `/api/order/po/${pk}/`, + { + supplier_detail: true, + }, + { + success: function(response) { + var text = global_settings.PURCHASEORDER_REFERENCE_PREFIX || ''; + + text += response.reference; + + if (response.supplier_detail) { + text += ` ${response.supplier_detail.name}`; + } + + var dropdown = `#id-purchase-order-${supplier}`; + + var option = new Option(text, pk, true, true); + + $('#modal-form').find(dropdown).append(option).trigger('change'); + } + } + ) + } + }); } function editPurchaseOrderLineItem(e) {