From 80d46fb3abc416bfc442faa2cbee6962fc2a5587 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 22 Apr 2021 12:30:38 +0200 Subject: [PATCH] cleanup; using one currency --- .../part/templates/part/part_pricing.html | 165 +++++++++++------- InvenTree/part/views.py | 17 +- 2 files changed, 115 insertions(+), 67 deletions(-) diff --git a/InvenTree/part/templates/part/part_pricing.html b/InvenTree/part/templates/part/part_pricing.html index b07be7bdba..9e29074e39 100644 --- a/InvenTree/part/templates/part/part_pricing.html +++ b/InvenTree/part/templates/part/part_pricing.html @@ -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 %}
@@ -81,73 +82,111 @@ {% endif %} {% if show_graph and price_history %} -

{% trans 'Stock Pricing' %}

- {% if price_history|length > 1 %} - - - {% else %} -
- {% trans 'No stock pricing history is available for this part.' %} -
- {% endif %} + }); + + {% else %} +
+ {% trans 'No stock pricing history is available for this part.' %} +
+ {% endif %} {% endif %} {% if min_unit_buy_price or min_unit_bom_price %} diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 8113a52993..32bb8361b5 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -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