2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-30 20:46:47 +00:00

Add more information to scheduling chart

Also improves chart styling
This commit is contained in:
Oliver 2022-03-01 23:20:08 +11:00
parent 776dffe779
commit f33f1a339d
2 changed files with 27 additions and 4 deletions

View File

@ -453,7 +453,7 @@ class PartScheduling(generics.RetrieveAPIView):
schedule = [] schedule = []
def add_schedule_entry(date, quantity, label, url): def add_schedule_entry(date, quantity, title, label, url):
""" """
Check if a scheduled entry should be added: Check if a scheduled entry should be added:
- date must be non-null - date must be non-null
@ -465,8 +465,9 @@ class PartScheduling(generics.RetrieveAPIView):
schedule.append({ schedule.append({
'date': date, 'date': date,
'quantity': quantity, 'quantity': quantity,
'url': url, 'title': title,
'label': label, 'label': label,
'url': url,
}) })
# Add purchase order (incoming stock) information # Add purchase order (incoming stock) information
@ -484,6 +485,7 @@ class PartScheduling(generics.RetrieveAPIView):
add_schedule_entry( add_schedule_entry(
target_date, target_date,
quantity, quantity,
_('Incoming Purchase Order'),
str(line.order), str(line.order),
line.order.get_absolute_url() line.order.get_absolute_url()
) )
@ -503,6 +505,7 @@ class PartScheduling(generics.RetrieveAPIView):
add_schedule_entry( add_schedule_entry(
target_date, target_date,
-quantity, -quantity,
_('Outgoing Sales Order'),
str(line.order), str(line.order),
line.order.get_absolute_url(), line.order.get_absolute_url(),
) )
@ -520,6 +523,7 @@ class PartScheduling(generics.RetrieveAPIView):
add_schedule_entry( add_schedule_entry(
build.target_date, build.target_date,
quantity, quantity,
_('Stock produced by Build Order'),
str(build), str(build),
build.get_absolute_url(), build.get_absolute_url(),
) )
@ -551,6 +555,7 @@ class PartScheduling(generics.RetrieveAPIView):
add_schedule_entry( add_schedule_entry(
allocation.build.target_date, allocation.build.target_date,
-allocation.quantity, -allocation.quantity,
_('Stock required for Build Order'),
str(allocation.build), str(allocation.build),
allocation.build.get_absolute_url(), allocation.build.get_absolute_url(),
) )

View File

@ -1999,6 +1999,7 @@ function loadPartSchedulingChart(canvas_id, part_id) {
{ {
date: today, date: today,
delta: 0, delta: 0,
label: '{% trans "Current Stock" %}',
} }
]; ];
@ -2016,6 +2017,7 @@ function loadPartSchedulingChart(canvas_id, part_id) {
stock_schedule.push({ stock_schedule.push({
date: moment(entry.date), date: moment(entry.date),
delta: entry.quantity, delta: entry.quantity,
title: entry.title,
label: entry.label, label: entry.label,
url: entry.url, url: entry.url,
}) })
@ -2042,7 +2044,9 @@ function loadPartSchedulingChart(canvas_id, part_id) {
datasets: [{ datasets: [{
label: '{% trans "Scheduled Stock Quantities" %}', label: '{% trans "Scheduled Stock Quantities" %}',
data: stock_schedule, data: stock_schedule,
backgroundColor: 'rgb(255, 99, 132)' backgroundColor: 'rgb(220, 160, 80)',
borderWidth: 2,
borderColor: 'rgb(90, 130, 150)'
}], }],
}; };
@ -2069,7 +2073,21 @@ function loadPartSchedulingChart(canvas_id, part_id) {
tooltip: { tooltip: {
callbacks: { callbacks: {
label: function(item) { label: function(item) {
return renderLink(item.raw.label, item.raw.url); return item.raw.label;
},
beforeLabel: function(item) {
return item.raw.title;
},
afterLabel: function(item) {
var delta = item.raw.delta;
if (delta == 0) {
delta = '';
} else {
delta = ` (${item.raw.delta > 0 ? "+" : ""}${item.raw.delta})`;
}
return `{% trans "Quantity" %}: ${item.raw.y}${delta}`;
} }
} }
} }