mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-29 18:20:53 +00:00
Currency API Updates (#4300)
* Adds an API endpoint for manually updating / refreshing currency data from the server * Update currency rates manually from the settings page * Add 'last updated' information to the currency exchange backend * Load currency exchange data via API (on setings page) * Bump API version * Table cleanup
This commit is contained in:
InvenTree
InvenTree
common
templates
InvenTree
settings
@ -11,6 +11,7 @@
|
||||
<div class='panel-content'>
|
||||
<table class='table table-striped table-condensed'>
|
||||
<tbody>
|
||||
{% include "InvenTree/settings/setting.html" with key="INVENTREE_DEFAULT_CURRENCY" icon="fa-globe" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PART_INTERNAL_PRICE" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PART_BOM_USE_INTERNAL_PRICE" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PRICING_DECIMAL_PLACES" %}
|
||||
@ -29,54 +30,27 @@
|
||||
|
||||
<div class='panel-heading'>
|
||||
<div class='d-flex flex-wrap'>
|
||||
<h4>{% trans "Currency Settings" %}</h4>
|
||||
<h4>{% trans "Exchange Rates" %}</h4>
|
||||
{% include "spacer.html" %}
|
||||
<div class='btn-group' role='group'>
|
||||
<form action='{% url "settings-currencies-refresh" %}' method='post'>
|
||||
<div id='refresh-rates-form'>
|
||||
{% csrf_token %}
|
||||
<button type='submit' id='update-rates' class='btn btn-primary float-right'>{% trans "Update Now" %}</button>
|
||||
</div>
|
||||
</form>
|
||||
<button type='button' id='btn-update-rates' class='btn btn-primary float-right'>
|
||||
<span class='fas fa-sync-alt'></span> {% trans "Update Now" %}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class='panel-content'>
|
||||
{% if rates_updated %}
|
||||
<div class='alert alert-block alert-info'>
|
||||
{% trans "Last Update" %} - {{ rates_updated }}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class='alert alert-block alert-warning'>
|
||||
{% trans "Last Update" %} - {% trans "Never" %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class='alert alert-block alert-info'>
|
||||
{% trans "Last Update" %} - {{ rates_updated }}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class='alert alert-block alert-warning'>
|
||||
{% trans "Last Update" %} - {% trans "Never" %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<table class='table table-striped table-condensed'>
|
||||
<tbody>
|
||||
{% include "InvenTree/settings/setting.html" with key="INVENTREE_DEFAULT_CURRENCY" icon="fa-globe" %}
|
||||
<table class='table table-striped table-condensed' id='exchange-rate-table'></table>
|
||||
|
||||
<tr>
|
||||
<td></td>
|
||||
<th>{% trans "Base Currency" %}</th>
|
||||
<th>{{ base_currency }}</th>
|
||||
<th colspan='2'></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<th>{% trans "Exchange Rates" %}</th>
|
||||
<th>{% trans "Currency" %}</th>
|
||||
<th>{% trans "Rate" %}</th>
|
||||
</tr>
|
||||
{% for rate in rates %}
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>{{ rate.currency }}</td>
|
||||
<td>{{ rate.value }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endblock panel_content %}
|
||||
|
@ -151,6 +151,52 @@ $("#edit-password").on('click', function() {
|
||||
);
|
||||
});
|
||||
|
||||
$('#btn-update-rates').click(function() {
|
||||
inventreePut(
|
||||
'{% url "api-currency-refresh" %}',
|
||||
{},
|
||||
{
|
||||
method: 'POST',
|
||||
success: function(data) {
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$('#exchange-rate-table').inventreeTable({
|
||||
url: '{% url "api-currency-exchange" %}',
|
||||
search: false,
|
||||
showColumns: false,
|
||||
sortable: true,
|
||||
sidePagination: 'client',
|
||||
onLoadSuccess: function(response) {
|
||||
var data = response.exchange_rates || {};
|
||||
|
||||
var rows = [];
|
||||
|
||||
for (var currency in data) {
|
||||
rows.push({
|
||||
'currency': currency,
|
||||
'rate': data[currency],
|
||||
});
|
||||
}
|
||||
|
||||
$('#exchange-rate-table').bootstrapTable('load', rows);
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'currency',
|
||||
sortable: true,
|
||||
title: '{% trans "Currency" %}',
|
||||
},
|
||||
{
|
||||
field: 'rate',
|
||||
sortable: true,
|
||||
title: '{% trans "Rate" %}',
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
$('#category-select').select2({
|
||||
placeholder: '',
|
||||
|
Reference in New Issue
Block a user