mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
cleanup; using one currency
This commit is contained in:
parent
a0154067d2
commit
80d46fb3ab
@ -4,6 +4,7 @@
|
||||
{% load inventree_extras %}
|
||||
{% block pre_form_content %}
|
||||
|
||||
{% settings_value "INVENTREE_DEFAULT_CURRENCY" as currency %}
|
||||
{% settings_value "PART_SHOW_GRAPH" as show_graph %}
|
||||
|
||||
<div class='alert alert-info alert-block'>
|
||||
@ -83,14 +84,19 @@
|
||||
{% if show_graph and price_history %}
|
||||
<h4>{% trans 'Stock Pricing' %}</h4>
|
||||
{% if price_history|length > 1 %}
|
||||
<canvas id="priceChart"></canvas>
|
||||
<div style="height: 300px">
|
||||
<canvas id="StockPriceChart"></canvas>
|
||||
</div>
|
||||
<div class='alert alert-info alert-block'>
|
||||
{% blocktrans %}All prices are converted from their original currencies to {{currency}} at the current conversion-rate.{% endblocktrans %}
|
||||
</div>
|
||||
<script>
|
||||
var pricedata = {
|
||||
labels: [
|
||||
{% for line in price_history %}'{{ line.date }}',{% endfor %}
|
||||
],
|
||||
datasets: [{
|
||||
label: 'Price',
|
||||
label: '{% trans "Single Price" %}',
|
||||
backgroundColor: 'rgba(255, 99, 132, 0.2)',
|
||||
borderColor: 'rgb(255, 99, 132)',
|
||||
yAxisID: 'y',
|
||||
@ -100,8 +106,32 @@
|
||||
borderWidth: 1,
|
||||
type: 'line'
|
||||
},
|
||||
{% if 'price_diff' in price_history.0 %}
|
||||
{
|
||||
label: 'Qty',
|
||||
label: '{% trans "Single Price Difference" %}',
|
||||
backgroundColor: 'rgba(68, 157, 68, 0.2)',
|
||||
borderColor: 'rgb(68, 157, 68)',
|
||||
yAxisID: 'y2',
|
||||
data: [
|
||||
{% for line in price_history %}{{ line.price_diff|stringformat:".2f" }},{% endfor %}
|
||||
],
|
||||
borderWidth: 1,
|
||||
type: 'line'
|
||||
},
|
||||
{
|
||||
label: '{% trans "Part Single Price" %}',
|
||||
backgroundColor: 'rgba(70, 127, 155, 0.2)',
|
||||
borderColor: 'rgb(70, 127, 155)',
|
||||
yAxisID: 'y',
|
||||
data: [
|
||||
{% for line in price_history %}{{ line.price_part|stringformat:".2f" }},{% endfor %}
|
||||
],
|
||||
borderWidth: 1,
|
||||
type: 'line'
|
||||
},
|
||||
{% endif %}
|
||||
{
|
||||
label: '{% trans "Quantity" %}',
|
||||
backgroundColor: 'rgba(255, 206, 86, 0.2)',
|
||||
borderColor: 'rgb(255, 206, 86)',
|
||||
yAxisID: 'y1',
|
||||
@ -111,13 +141,13 @@
|
||||
borderWidth: 1
|
||||
}]
|
||||
}
|
||||
|
||||
var ctx = document.getElementById('priceChart');
|
||||
var priceChart = new Chart(ctx, {
|
||||
var ctx = document.getElementById('StockPriceChart');
|
||||
var StockPriceChart = new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: pricedata,
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
plugins: {legend: {position: 'bottom'}},
|
||||
scales: {
|
||||
y: {
|
||||
@ -126,7 +156,7 @@
|
||||
grid: {display: false},
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Price - USD'
|
||||
text: '{% blocktrans %}Single Price - {{currency}}{% endblocktrans %}'
|
||||
}
|
||||
},
|
||||
y1: {
|
||||
@ -135,11 +165,20 @@
|
||||
grid: {display: false},
|
||||
titel: {
|
||||
display: true,
|
||||
text: 'Qty',
|
||||
text: '{% trans "Quantity" %}',
|
||||
position: 'right'
|
||||
}
|
||||
},
|
||||
y2: {
|
||||
type: 'linear',
|
||||
position: 'left',
|
||||
grid: {display: false},
|
||||
title: {
|
||||
display: true,
|
||||
text: '{% blocktrans %}Single Price Difference- {{currency}}{% endblocktrans %}'
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -19,6 +19,7 @@ from django.forms import HiddenInput, CheckboxInput
|
||||
from django.conf import settings
|
||||
|
||||
from moneyed import CURRENCIES
|
||||
from djmoney.contrib.exchange.models import convert_money
|
||||
|
||||
from PIL import Image
|
||||
|
||||
@ -2042,18 +2043,26 @@ class PartPricing(AjaxView):
|
||||
for stock_item in stock:
|
||||
if None in [stock_item.purchase_price, stock_item.quantity]:
|
||||
continue
|
||||
|
||||
# convert purchase price to current currency - only one currency in the graph
|
||||
price = convert_money(stock_item.purchase_price, inventree_settings.currency_code_default())
|
||||
line = {
|
||||
'price': stock_item.purchase_price.amount,
|
||||
'price': price.amount,
|
||||
'qty': stock_item.quantity
|
||||
}
|
||||
# Supplier Part Name # TODO use in graph
|
||||
if stock_item.supplier_part:
|
||||
line['name'] = stock_item.supplier_part.pretty_name
|
||||
|
||||
if stock_item.supplier_part.unit_pricing and stock_item.purchase_price:
|
||||
line['price_diff'] = stock_item.supplier_part.unit_pricing - stock_item.purchase_price.amount
|
||||
if stock_item.purchase_order:
|
||||
if stock_item.supplier_part.unit_pricing and price:
|
||||
line['price_diff'] = price.amount - stock_item.supplier_part.unit_pricing
|
||||
line['price_part'] = stock_item.supplier_part.unit_pricing
|
||||
|
||||
# set date for graph labels
|
||||
if stock_item.purchase_order:
|
||||
line['date'] = stock_item.purchase_order.issue_date.strftime('%d.%m.%Y')
|
||||
else:
|
||||
line['date'] = stock_item.tracking_info.first().date.strftime('%d.%m.%Y')
|
||||
ret.append(line)
|
||||
|
||||
ctx['price_history'] = ret
|
||||
|
Loading…
Reference in New Issue
Block a user