mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
bom-price ranges as pie-chart
This commit is contained in:
parent
3363969c17
commit
b4c9edcd27
@ -97,7 +97,16 @@
|
|||||||
{% trans 'No pricing information is available for this part.' %}
|
{% trans 'No pricing information is available for this part.' %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div></div>
|
</div>
|
||||||
|
{% if part.bom_count > 0 %}
|
||||||
|
<div class="col col-md-6">
|
||||||
|
<h4>{% trans 'BOM Pricing' %}</h4>
|
||||||
|
<div style="max-width: 99%;">
|
||||||
|
<canvas id="BomChart"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
{% if price_history %}
|
{% if price_history %}
|
||||||
<hr>
|
<hr>
|
||||||
@ -122,7 +131,6 @@ the part single price shown is the current price for that supplier part"></i></h
|
|||||||
{{ block.super }}
|
{{ block.super }}
|
||||||
|
|
||||||
{% settings_value "INVENTREE_DEFAULT_CURRENCY" as currency %}
|
{% settings_value "INVENTREE_DEFAULT_CURRENCY" as currency %}
|
||||||
|
|
||||||
{% if price_history %}
|
{% if price_history %}
|
||||||
var pricedata = {
|
var pricedata = {
|
||||||
labels: [
|
labels: [
|
||||||
@ -174,8 +182,27 @@ the part single price shown is the current price for that supplier part"></i></h
|
|||||||
borderWidth: 1
|
borderWidth: 1
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
var ctx = document.getElementById('StockPriceChart');
|
var StockPriceChart = loadStockPricingChart(document.getElementById('StockPriceChart'), pricedata)
|
||||||
var StockPriceChart = loadStockPricingChart(ctx, pricedata)
|
var bom_colors = randomColor({hue: 'green', count: {{ bom_parts|length }} })
|
||||||
|
var bomdata = {
|
||||||
|
labels: [{% for line in bom_parts %}'{{ line.name }}',{% endfor %}],
|
||||||
|
datasets: [
|
||||||
|
{% if bom_pie_min %}
|
||||||
|
{
|
||||||
|
label: 'Max Price',
|
||||||
|
data: [{% for line in bom_parts %}{{ line.max_price }},{% endfor %}],
|
||||||
|
backgroundColor: bom_colors,
|
||||||
|
},
|
||||||
|
{% endif %}
|
||||||
|
{
|
||||||
|
label: 'Price',
|
||||||
|
data: [{% for line in bom_parts %}{% if bom_pie_min %}{{ line.min_price }}{% else %}{{ line.price }}{% endif%},{% endfor %}],
|
||||||
|
backgroundColor: bom_colors,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
var BomChart = loadBomChart(document.getElementById('BomChart'), bomdata)
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -845,6 +845,19 @@ class PartPricingView(PartDetail):
|
|||||||
|
|
||||||
ctx['price_history'] = ret
|
ctx['price_history'] = ret
|
||||||
|
|
||||||
|
# BOM Information for Pie-Chart
|
||||||
|
bom_items = [{'name': str(a.sub_part), 'price': a.sub_part.get_price_range(quantity), 'q': a.quantity} for a in part.bom_items.all()]
|
||||||
|
if [True for a in bom_items if len(set(a['price']))==2]:
|
||||||
|
ctx['bom_parts'] = [{
|
||||||
|
'name': a['name'],
|
||||||
|
'min_price': str((a['price'][0] * a['q'])/ quantity),
|
||||||
|
'max_price': str((a['price'][1] * a['q']) / quantity)} for a in bom_items]
|
||||||
|
ctx['bom_pie_min'] = True
|
||||||
|
else:
|
||||||
|
ctx['bom_parts'] = [{
|
||||||
|
'name':a['name'],
|
||||||
|
'price': str((a['price'][0] * a['q']) / quantity)} for a in bom_items]
|
||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
def get_initials(self):
|
def get_initials(self):
|
||||||
|
@ -731,3 +731,17 @@ function loadStockPricingChart(context, data) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function loadBomChart(context, data) {
|
||||||
|
return new Chart(context, {
|
||||||
|
type: 'doughnut',
|
||||||
|
data: data,
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
plugins: {legend: {position: 'bottom'},
|
||||||
|
scales: {xAxes: [{beginAtZero: true, ticks: {autoSkip: false}}]}}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user