From 42af52ee51a2bf402a80ea1b7d056ae4092f956c Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 24 Aug 2021 22:31:13 +1000 Subject: [PATCH] WIP --- .../order/templates/order/order_base.html | 5 + InvenTree/templates/js/translated/order.js | 141 +++++++++++++++++- 2 files changed, 145 insertions(+), 1 deletion(-) diff --git a/InvenTree/order/templates/order/order_base.html b/InvenTree/order/templates/order/order_base.html index 0d46207c33..e0228ac949 100644 --- a/InvenTree/order/templates/order/order_base.html +++ b/InvenTree/order/templates/order/order_base.html @@ -188,6 +188,11 @@ $("#edit-order").click(function() { }); $("#receive-order").click(function() { + + receivePurchaseOrder({{ order.pk }}); + + return; + launchModalForm("{% url 'po-receive' order.id %}", { reload: true, secondary: [ diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js index c6dd773373..d304b1c42b 100644 --- a/InvenTree/templates/js/translated/order.js +++ b/InvenTree/templates/js/translated/order.js @@ -103,6 +103,146 @@ function removeOrderRowFromOrderWizard(e) { $('#' + row).remove(); } + +function receivePurchaseOrder(orderId, options={}) { + /* Receive parts against a purchase order. + * Launches a modal form. + * + * Required Args: + * - orderId: pk value for the PurchaseOrder + * + * Optional Args: + * - lines: List of purchase order lines to receive + * (If omitted, lines will be requested via the API) + */ + + // List of lines to receive + var selectedLines = options.lines || []; + + // List of line items to receive + var lineItems = []; + + inventreeGet( + '{% url "api-po-line-list" %}', + { + order: orderId, + part_detail: true, + }, + { + success: function(results) { + for (var idx = 0; idx < results.length; idx++) { + var line = results[idx]; + + // Skip / ignore lines missing part information + if (!line.part || !line.supplier_part_detail.part) { + continue; + } + + // Skip / ignore lines which are fully received + if (line.received >= line.quantity) { + continue; + } + + if (selectedLines.length == 0 || selectedLines.includes(line.pk)) { + lineItems.push(line); + } + } + + // Construct a form for processing + var html = ` + + + + + + + + + + + + + +
{% trans "Part" %}{% trans "SKU" %}{% trans "On Order" %}{% trans "Received" %}{% trans "Quantity" %}{% trans "Status" %}{% trans "Destination" %}
+ `; + + constructForm(`/api/order/po/${orderId}/receive/`, { + method: 'POST', + title: '{% trans "Receive Items" %}', + confirm: true, + fields: { + location: {}, + }, + preFormContent: html, + afterRender: function(fields, options) { + + var table = $(options.modal).find('#line-items-table').children('tbody'); + + options.hideLabels = true; + + var parameters = {}; + + // Insert a row for each item + lineItems.forEach(function(item) { + + var part = item.part_detail; + var supplier_part = item.supplier_part_detail; + + var row = ''; + + // Part detail + row += `${thumbnailImage(part.thumbnail)} ${part.full_name}`; + + // Order code + row += `${supplier_part.SKU}`; + + // Quantity on order + row += `${line.quantity}`; + + // Quantity received + row += `${line.received}`; + + parameters = fields.items.child.children.quantity; + parameters.value = line.quantity - line.received; + + // Quantity input + row += tdWrap(constructField( + `quantity_${line.pk}`, + parameters, + options + )); + + // Status input + row += tdWrap(constructField( + `status_${line.pk}`, + fields.items.child.children.status, + options + )); + + // Location input + row += tdWrap(constructField( + `location_${line.pk}`, + fields.items.child.children.location, + options + )); + + table.append(trWrap(row)); + + parameters = fields.items.child.children.location; + + parameters.name = `location_${line.pk}`; + + initializeRelatedField(parameters, fields, options); + + }); + } + }); + } + } + ); +} + + function newSupplierPartFromOrderWizard(e) { /* Create a new supplier part directly from an order form. * Launches a secondary modal and (if successful), @@ -117,7 +257,6 @@ function newSupplierPartFromOrderWizard(e) { if (!part) { part = $(src).closest('button').attr('part'); - console.log('parent: ' + part); } createSupplierPart({