mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-03 05:48:47 +00:00
cleanup; using one currency
This commit is contained in:
parent
a0154067d2
commit
80d46fb3ab
@ -4,6 +4,7 @@
|
|||||||
{% load inventree_extras %}
|
{% load inventree_extras %}
|
||||||
{% block pre_form_content %}
|
{% block pre_form_content %}
|
||||||
|
|
||||||
|
{% settings_value "INVENTREE_DEFAULT_CURRENCY" as currency %}
|
||||||
{% settings_value "PART_SHOW_GRAPH" as show_graph %}
|
{% settings_value "PART_SHOW_GRAPH" as show_graph %}
|
||||||
|
|
||||||
<div class='alert alert-info alert-block'>
|
<div class='alert alert-info alert-block'>
|
||||||
@ -81,73 +82,111 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if show_graph and price_history %}
|
{% if show_graph and price_history %}
|
||||||
<h4>{% trans 'Stock Pricing' %}</h4>
|
<h4>{% trans 'Stock Pricing' %}</h4>
|
||||||
{% if price_history|length > 1 %}
|
{% if price_history|length > 1 %}
|
||||||
<canvas id="priceChart"></canvas>
|
<div style="height: 300px">
|
||||||
<script>
|
<canvas id="StockPriceChart"></canvas>
|
||||||
var pricedata = {
|
</div>
|
||||||
labels: [
|
<div class='alert alert-info alert-block'>
|
||||||
{% for line in price_history %}'{{ line.date }}',{% endfor %}
|
{% blocktrans %}All prices are converted from their original currencies to {{currency}} at the current conversion-rate.{% endblocktrans %}
|
||||||
],
|
</div>
|
||||||
datasets: [{
|
<script>
|
||||||
label: 'Price',
|
var pricedata = {
|
||||||
backgroundColor: 'rgba(255, 99, 132, 0.2)',
|
labels: [
|
||||||
borderColor: 'rgb(255, 99, 132)',
|
{% for line in price_history %}'{{ line.date }}',{% endfor %}
|
||||||
yAxisID: 'y',
|
|
||||||
data: [
|
|
||||||
{% for line in price_history %}{{ line.price|stringformat:".2f" }},{% endfor %}
|
|
||||||
],
|
],
|
||||||
borderWidth: 1,
|
datasets: [{
|
||||||
type: 'line'
|
label: '{% trans "Single Price" %}',
|
||||||
},
|
backgroundColor: 'rgba(255, 99, 132, 0.2)',
|
||||||
{
|
borderColor: 'rgb(255, 99, 132)',
|
||||||
label: 'Qty',
|
yAxisID: 'y',
|
||||||
backgroundColor: 'rgba(255, 206, 86, 0.2)',
|
data: [
|
||||||
borderColor: 'rgb(255, 206, 86)',
|
{% for line in price_history %}{{ line.price|stringformat:".2f" }},{% endfor %}
|
||||||
yAxisID: 'y1',
|
],
|
||||||
data: [
|
borderWidth: 1,
|
||||||
{% for line in price_history %}{{ line.qty|stringformat:"f" }},{% endfor %}
|
type: 'line'
|
||||||
],
|
},
|
||||||
borderWidth: 1
|
{% if 'price_diff' in price_history.0 %}
|
||||||
}]
|
{
|
||||||
}
|
label: '{% trans "Single Price Difference" %}',
|
||||||
|
backgroundColor: 'rgba(68, 157, 68, 0.2)',
|
||||||
var ctx = document.getElementById('priceChart');
|
borderColor: 'rgb(68, 157, 68)',
|
||||||
var priceChart = new Chart(ctx, {
|
yAxisID: 'y2',
|
||||||
type: 'bar',
|
data: [
|
||||||
data: pricedata,
|
{% for line in price_history %}{{ line.price_diff|stringformat:".2f" }},{% endfor %}
|
||||||
options: {
|
],
|
||||||
responsive: true,
|
borderWidth: 1,
|
||||||
plugins: {legend: {position: 'bottom'}},
|
type: 'line'
|
||||||
scales: {
|
},
|
||||||
y: {
|
{
|
||||||
type: 'linear',
|
label: '{% trans "Part Single Price" %}',
|
||||||
position: 'left',
|
backgroundColor: 'rgba(70, 127, 155, 0.2)',
|
||||||
grid: {display: false},
|
borderColor: 'rgb(70, 127, 155)',
|
||||||
title: {
|
yAxisID: 'y',
|
||||||
display: true,
|
data: [
|
||||||
text: 'Price - USD'
|
{% 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',
|
||||||
|
data: [
|
||||||
|
{% for line in price_history %}{{ line.qty|stringformat:"f" }},{% endfor %}
|
||||||
|
],
|
||||||
|
borderWidth: 1
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
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: {
|
||||||
|
type: 'linear',
|
||||||
|
position: 'left',
|
||||||
|
grid: {display: false},
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
text: '{% blocktrans %}Single Price - {{currency}}{% endblocktrans %}'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
y1: {
|
||||||
|
type: 'linear',
|
||||||
|
position: 'right',
|
||||||
|
grid: {display: false},
|
||||||
|
titel: {
|
||||||
|
display: true,
|
||||||
|
text: '{% trans "Quantity" %}',
|
||||||
|
position: 'right'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
y2: {
|
||||||
|
type: 'linear',
|
||||||
|
position: 'left',
|
||||||
|
grid: {display: false},
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
text: '{% blocktrans %}Single Price Difference- {{currency}}{% endblocktrans %}'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
y1: {
|
|
||||||
type: 'linear',
|
|
||||||
position: 'right',
|
|
||||||
grid: {display: false},
|
|
||||||
titel: {
|
|
||||||
display: true,
|
|
||||||
text: 'Qty',
|
|
||||||
position: 'right'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
</script>
|
||||||
</script>
|
{% else %}
|
||||||
{% else %}
|
<div class='alert alert-danger alert-block'>
|
||||||
<div class='alert alert-danger alert-block'>
|
{% trans 'No stock pricing history is available for this part.' %}
|
||||||
{% trans 'No stock pricing history is available for this part.' %}
|
</div>
|
||||||
</div>
|
{% endif %}
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if min_unit_buy_price or min_unit_bom_price %}
|
{% if min_unit_buy_price or min_unit_bom_price %}
|
||||||
|
@ -19,6 +19,7 @@ from django.forms import HiddenInput, CheckboxInput
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from moneyed import CURRENCIES
|
from moneyed import CURRENCIES
|
||||||
|
from djmoney.contrib.exchange.models import convert_money
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
@ -2042,18 +2043,26 @@ class PartPricing(AjaxView):
|
|||||||
for stock_item in stock:
|
for stock_item in stock:
|
||||||
if None in [stock_item.purchase_price, stock_item.quantity]:
|
if None in [stock_item.purchase_price, stock_item.quantity]:
|
||||||
continue
|
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 = {
|
line = {
|
||||||
'price': stock_item.purchase_price.amount,
|
'price': price.amount,
|
||||||
'qty': stock_item.quantity
|
'qty': stock_item.quantity
|
||||||
}
|
}
|
||||||
|
# Supplier Part Name # TODO use in graph
|
||||||
if stock_item.supplier_part:
|
if stock_item.supplier_part:
|
||||||
line['name'] = stock_item.supplier_part.pretty_name
|
line['name'] = stock_item.supplier_part.pretty_name
|
||||||
|
|
||||||
if stock_item.supplier_part.unit_pricing and stock_item.purchase_price:
|
if stock_item.supplier_part.unit_pricing and price:
|
||||||
line['price_diff'] = stock_item.supplier_part.unit_pricing - stock_item.purchase_price.amount
|
line['price_diff'] = price.amount - stock_item.supplier_part.unit_pricing
|
||||||
if stock_item.purchase_order:
|
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')
|
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)
|
ret.append(line)
|
||||||
|
|
||||||
ctx['price_history'] = ret
|
ctx['price_history'] = ret
|
||||||
|
Loading…
x
Reference in New Issue
Block a user