mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 04:26:44 +00:00
Fix bug in recent part scheduling table (#3566)
* Gotta make a variable to reference a variable * Fix scaling issues * Hey, it's only a suggestion * Fix quantity display in build order table * Logic fix for destroying / refreshing chart * Better handling of edge cases * Fix issue with "undefined" labels * Speculative should be a question mark
This commit is contained in:
parent
b70a0164ae
commit
7384a85bdb
@ -435,8 +435,12 @@
|
|||||||
var chart = loadPartSchedulingChart('part-schedule-chart', {{ part.pk }});
|
var chart = loadPartSchedulingChart('part-schedule-chart', {{ part.pk }});
|
||||||
|
|
||||||
$('#btn-schedule-reload').click(function() {
|
$('#btn-schedule-reload').click(function() {
|
||||||
|
|
||||||
|
if (chart != null) {
|
||||||
chart.destroy();
|
chart.destroy();
|
||||||
loadPartSchedulingChart('part-schedule-chart', {{ part.pk }});
|
}
|
||||||
|
|
||||||
|
chart = loadPartSchedulingChart('part-schedule-chart', {{ part.pk }});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1831,6 +1831,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
|
|||||||
var available_stock = availableQuantity(row);
|
var available_stock = availableQuantity(row);
|
||||||
|
|
||||||
var required = requiredQuantity(row);
|
var required = requiredQuantity(row);
|
||||||
|
var allocated = allocatedQuantity(row);
|
||||||
|
|
||||||
var text = '';
|
var text = '';
|
||||||
|
|
||||||
@ -1838,7 +1839,7 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
|
|||||||
text += `${available_stock}`;
|
text += `${available_stock}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (available_stock < required) {
|
if (available_stock < (required - allocated)) {
|
||||||
text += `<span class='fas fa-times-circle icon-red float-right' title='{% trans "Insufficient stock available" %}'></span>`;
|
text += `<span class='fas fa-times-circle icon-red float-right' title='{% trans "Insufficient stock available" %}'></span>`;
|
||||||
} else {
|
} else {
|
||||||
text += `<span class='fas fa-check-circle icon-green float-right' title='{% trans "Sufficient stock available" %}'></span>`;
|
text += `<span class='fas fa-check-circle icon-green float-right' title='{% trans "Sufficient stock available" %}'></span>`;
|
||||||
|
@ -2269,6 +2269,8 @@ function loadPartSchedulingChart(canvas_id, part_id) {
|
|||||||
|
|
||||||
var part_info = null;
|
var part_info = null;
|
||||||
|
|
||||||
|
var was_error = false;
|
||||||
|
|
||||||
// First, grab updated data for the particular part
|
// First, grab updated data for the particular part
|
||||||
inventreeGet(`/api/part/${part_id}/`, {}, {
|
inventreeGet(`/api/part/${part_id}/`, {}, {
|
||||||
async: false,
|
async: false,
|
||||||
@ -2302,6 +2304,8 @@ function loadPartSchedulingChart(canvas_id, part_id) {
|
|||||||
var initial_stock_min = part_info.in_stock;
|
var initial_stock_min = part_info.in_stock;
|
||||||
var initial_stock_max = part_info.in_stock;
|
var initial_stock_max = part_info.in_stock;
|
||||||
|
|
||||||
|
var n_entries = 0;
|
||||||
|
|
||||||
/* Request scheduling information for the part.
|
/* Request scheduling information for the part.
|
||||||
* Note that this information has already been 'curated' by the server,
|
* Note that this information has already been 'curated' by the server,
|
||||||
* and arranged in increasing chronological order
|
* and arranged in increasing chronological order
|
||||||
@ -2313,6 +2317,8 @@ function loadPartSchedulingChart(canvas_id, part_id) {
|
|||||||
async: false,
|
async: false,
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
|
|
||||||
|
n_entries = response.length;
|
||||||
|
|
||||||
for (var idx = 0; idx < response.length; idx++) {
|
for (var idx = 0; idx < response.length; idx++) {
|
||||||
|
|
||||||
var entry = response[idx];
|
var entry = response[idx];
|
||||||
@ -2330,7 +2336,7 @@ function loadPartSchedulingChart(canvas_id, part_id) {
|
|||||||
var quantity_string = entry.quantity + entry.speculative_quantity;
|
var quantity_string = entry.quantity + entry.speculative_quantity;
|
||||||
|
|
||||||
if (entry.speculative_quantity != 0) {
|
if (entry.speculative_quantity != 0) {
|
||||||
quantity_string += `<span class='fas fa-info-circle icon-blue float-right' title='{% trans "Speculative" %}'></span>`;
|
quantity_string += `<span class='fas fa-question-circle icon-blue float-right' title='{% trans "Speculative" %}'></span>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add an entry to the scheduling table
|
// Add an entry to the scheduling table
|
||||||
@ -2376,7 +2382,7 @@ function loadPartSchedulingChart(canvas_id, part_id) {
|
|||||||
|
|
||||||
// If no scheduling information is available for the part,
|
// If no scheduling information is available for the part,
|
||||||
// remove the chart and display a message instead
|
// remove the chart and display a message instead
|
||||||
if (quantity_scheduled.length <= 1) {
|
if (n_entries < 1) {
|
||||||
|
|
||||||
var message = `
|
var message = `
|
||||||
<div class='alert alert-block alert-info'>
|
<div class='alert alert-block alert-info'>
|
||||||
@ -2395,9 +2401,13 @@ function loadPartSchedulingChart(canvas_id, part_id) {
|
|||||||
|
|
||||||
canvas_element.closest('div').html(message);
|
canvas_element.closest('div').html(message);
|
||||||
|
|
||||||
|
$('#part-schedule-table').hide();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('#part-schedule-table').show();
|
||||||
|
|
||||||
var y_min = 0;
|
var y_min = 0;
|
||||||
var y_max = 0;
|
var y_max = 0;
|
||||||
|
|
||||||
@ -2435,22 +2445,44 @@ function loadPartSchedulingChart(canvas_id, part_id) {
|
|||||||
q_spec_min.push({
|
q_spec_min.push({
|
||||||
x: date,
|
x: date,
|
||||||
y: speculative_min,
|
y: speculative_min,
|
||||||
label: 'label',
|
label: '',
|
||||||
title: '',
|
title: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
q_spec_max.push({
|
q_spec_max.push({
|
||||||
x: date,
|
x: date,
|
||||||
y: speculative_max,
|
y: speculative_max,
|
||||||
label: 'label',
|
label: '',
|
||||||
title: '',
|
title: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update min / max values
|
// Update min / max values
|
||||||
if (quantity < y_min) y_min = quantity;
|
if (quantity < y_min) y_min = quantity;
|
||||||
if (quantity > y_max) y_max = quantity;
|
if (quantity > y_max) y_max = quantity;
|
||||||
|
|
||||||
|
if (speculative_min < y_min) y_min = speculative_min;
|
||||||
|
if (speculative_max > y_max) y_max = speculative_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add one extra data point at the end
|
||||||
|
var n = quantity_scheduled.length;
|
||||||
|
var final_date = quantity_scheduled[n - 1].date.add(1, 'd').format('YYYY-MM-DD');
|
||||||
|
|
||||||
|
quantity_scheduled.push({
|
||||||
|
x: final_date,
|
||||||
|
y: quantity_scheduled[n - 1].y,
|
||||||
|
});
|
||||||
|
|
||||||
|
q_spec_min.push({
|
||||||
|
x: final_date,
|
||||||
|
y: q_spec_min[n - 1].y,
|
||||||
|
});
|
||||||
|
|
||||||
|
q_spec_max.push({
|
||||||
|
x: final_date,
|
||||||
|
y: q_spec_max[n - 1].y,
|
||||||
|
});
|
||||||
|
|
||||||
var context = document.getElementById(canvas_id);
|
var context = document.getElementById(canvas_id);
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
@ -2487,7 +2519,7 @@ function loadPartSchedulingChart(canvas_id, part_id) {
|
|||||||
// Construct a 'minimum stock' threshold line
|
// Construct a 'minimum stock' threshold line
|
||||||
var minimum_stock_curve = [
|
var minimum_stock_curve = [
|
||||||
{
|
{
|
||||||
x: today.format(),
|
x: quantity_scheduled[0].x,
|
||||||
y: part_info.minimum_stock,
|
y: part_info.minimum_stock,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -2513,11 +2545,21 @@ function loadPartSchedulingChart(canvas_id, part_id) {
|
|||||||
// Update the table
|
// Update the table
|
||||||
$('#part-schedule-table').find('tbody').html(table_html);
|
$('#part-schedule-table').find('tbody').html(table_html);
|
||||||
|
|
||||||
|
if (y_max < part_info.minimum_stock) {
|
||||||
|
y_max = part_info.minimum_stock;
|
||||||
|
}
|
||||||
|
|
||||||
var y_range = y_max - y_min;
|
var y_range = y_max - y_min;
|
||||||
|
|
||||||
y_max += 0.1 * y_range;
|
y_max += 0.1 * y_range;
|
||||||
y_min -= 0.1 * y_range;
|
y_min -= 0.1 * y_range;
|
||||||
|
|
||||||
|
// Prevent errors if y-scale is weird
|
||||||
|
if (y_max == y_min) {
|
||||||
|
y_min -= 1;
|
||||||
|
y_max += 1;
|
||||||
|
}
|
||||||
|
|
||||||
return new Chart(context, {
|
return new Chart(context, {
|
||||||
type: 'scatter',
|
type: 'scatter',
|
||||||
data: data,
|
data: data,
|
||||||
@ -2527,30 +2569,31 @@ function loadPartSchedulingChart(canvas_id, part_id) {
|
|||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
type: 'time',
|
type: 'time',
|
||||||
min: today.format(),
|
suggestedMin: today.format(),
|
||||||
|
suggestedMax: quantity_scheduled[quantity_scheduled.length - 1].x,
|
||||||
position: 'bottom',
|
position: 'bottom',
|
||||||
time: {
|
time: {
|
||||||
unit: 'day',
|
minUnit: 'day',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
y: {
|
y: {
|
||||||
min: y_min,
|
suggestedMin: y_min,
|
||||||
max: y_max,
|
suggestedMax: y_max,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: {
|
plugins: {
|
||||||
tooltip: {
|
tooltip: {
|
||||||
callbacks: {
|
callbacks: {
|
||||||
label: function(item) {
|
label: function(item) {
|
||||||
return item.raw.label;
|
return item.raw.label || '';
|
||||||
},
|
},
|
||||||
beforeLabel: function(item) {
|
beforeLabel: function(item) {
|
||||||
return item.raw.title;
|
return item.raw.title || '';
|
||||||
},
|
},
|
||||||
afterLabel: function(item) {
|
afterLabel: function(item) {
|
||||||
var delta = item.raw.delta;
|
var delta = item.raw.delta;
|
||||||
|
|
||||||
if (delta == 0) {
|
if (delta == null || delta == 0) {
|
||||||
delta = '';
|
delta = '';
|
||||||
} else {
|
} else {
|
||||||
delta = ` (${item.raw.delta > 0 ? '+' : ''}${item.raw.delta})`;
|
delta = ` (${item.raw.delta > 0 ? '+' : ''}${item.raw.delta})`;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user