mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Convert pricing data in stock table (#4417)
(cherry picked from commit 468a0f1fdf4c18a3d002e9dd7d511d2979c25115)
This commit is contained in:
parent
b6b701b077
commit
eefad0baca
@ -106,9 +106,9 @@ var cached_exchange_rates = null;
|
|||||||
/*
|
/*
|
||||||
* Retrieve currency conversion rate information from the server
|
* Retrieve currency conversion rate information from the server
|
||||||
*/
|
*/
|
||||||
function getCurrencyConversionRates() {
|
function getCurrencyConversionRates(cache=true) {
|
||||||
|
|
||||||
if (cached_exchange_rates != null) {
|
if (cache && cached_exchange_rates != null) {
|
||||||
return cached_exchange_rates;
|
return cached_exchange_rates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,6 +236,11 @@ function convertCurrency(value, source_currency, target_currency, rate_data) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rate_data == null) {
|
||||||
|
console.error('convertCurrency() called without rate_data');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!('base_currency' in rate_data)) {
|
if (!('base_currency' in rate_data)) {
|
||||||
console.error('Currency data missing base_currency parameter');
|
console.error('Currency data missing base_currency parameter');
|
||||||
return null;
|
return null;
|
||||||
|
@ -2041,9 +2041,27 @@ function loadStockTable(table, options) {
|
|||||||
title: '{% trans "Purchase Price" %}',
|
title: '{% trans "Purchase Price" %}',
|
||||||
sortable: false,
|
sortable: false,
|
||||||
formatter: function(value, row) {
|
formatter: function(value, row) {
|
||||||
return formatCurrency(value, {
|
let html = formatCurrency(value, {
|
||||||
currency: row.purchase_price_currency,
|
currency: row.purchase_price_currency,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var base = baseCurrency();
|
||||||
|
|
||||||
|
if (row.purchase_price_currency != base) {
|
||||||
|
let converted = convertCurrency(
|
||||||
|
row.purchase_price,
|
||||||
|
row.purchase_price_currency,
|
||||||
|
base,
|
||||||
|
getCurrencyConversionRates(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (converted) {
|
||||||
|
converted = formatCurrency(converted, {currency: baseCurrency()});
|
||||||
|
html += `<br><small><em>${converted}</em></small>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return html;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user