From 8f7164d5cdca6a8bcdffe3afa6ec5cf09e25b489 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 1 Mar 2022 17:24:09 +1100 Subject: [PATCH] Add information for outgoing stock (sales orders) --- InvenTree/templates/js/translated/part.js | 60 ++++++++++++++++++----- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index 83050d2e8c..301a761a7b 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -2008,8 +2008,6 @@ function loadPartSchedulingChart(canvas_id, part_id) { // First, iterate through to find an insertion index (based on date) var found = false; - console.log('addScheduleEntry:', date, delta, label); - for (var idx = 0; idx < stock_schedule.length; idx++) { var entry = stock_schedule[idx]; @@ -2021,8 +2019,6 @@ function loadPartSchedulingChart(canvas_id, part_id) { url: url, }); - console.log('found at idx:', idx); - found = true; break; } @@ -2052,8 +2048,6 @@ function loadPartSchedulingChart(canvas_id, part_id) { line_items.forEach(function(line_item) { - console.log('checking line:', line_item); - // Extract target_date information from the response. // If the line_item does not have an individual target date, maybe the parent order does? var target_date = line_item.target_date || line_item.order_detail.target_date; @@ -2061,19 +2055,20 @@ function loadPartSchedulingChart(canvas_id, part_id) { // How many to receive? var delta = Math.max(line_item.quantity - line_item.received, 0); + // TODO: What do we do if there is no target_date set for a PO line item? + // TODO: Do we just ignore it?? + if (target_date && delta > 0) { var td = moment(target_date); - - console.log("target date:", target_date); if (td >= today) { - // Attempt to insert the datapoint - - addScheduleEntry(td, delta, 'Purchase Order', '/index/'); + // TODO: Improve labels for purchase order lines + addScheduleEntry(td, delta, "Purchase Order", '/index/'); } else { // Ignore any entries that are in the "past" + // TODO: Can we better handle this case? } } }); @@ -2081,6 +2076,47 @@ function loadPartSchedulingChart(canvas_id, part_id) { } ); + // Extract sales order information from the server + if (part_info.salable) { + inventreeGet( + `/api/order/so-line/`, + { + part: part_id, + pending: true, + order_detail: true, + }, + { + async: false, + success: function(line_items) { + + line_items.forEach(function(line_item) { + + // Extract target_date information from the response. + // If the line_item does not have an individual target date, maybe the parent order does? + var target_date = line_item.target_date || line_item.order_detail.target_date; + + var delta = Math.max(line_item.quantity - line_item.shipped, 0); + + // TODO: What do we do if there is no target_date set for a PO line item? + // TODO: Do we just ignore it?? + + if (target_date && delta > 0) { + var td = moment(target_date); + + if (td >= today) { + // TODO: Improve labels for sales order items + addScheduleEntry(td, -delta, "Sales Order", '/index/'); + } else { + // Ignore any entries that are in the "past" + // TODO: Can we better handle this case? + } + } + }); + } + } + ); + } + // Iterate through future "events" to calculate expected quantity var quantity = part_info.in_stock; @@ -2097,7 +2133,7 @@ function loadPartSchedulingChart(canvas_id, part_id) { const data = { datasets: [{ - label: 'Scatter Dataset', + label: '{% trans "Scheduled Stock Quantities" %}', data: stock_schedule, backgroundColor: 'rgb(255, 99, 132)' }],