Added 'Currencies' settings view in global settings

This commit is contained in:
eeintech committed 2021-05-19 17:06:41 -04:00
1 parent 34ded08ee7
commit 6d5b2d3227
6 files changed
+66 -4

No files matched your search

+2 -2
View File
@@ -175,9 +175,9 @@ def update_exchange_rates():
# Get backend # Get backend
if 'InvenTreeManualExchangeBackend' in settings.EXCHANGE_BACKEND: if 'InvenTreeManualExchangeBackend' in settings.EXCHANGE_BACKEND:
backend = InvenTreeFixerExchangeBackend()
else:
backend = InvenTreeManualExchangeBackend() backend = InvenTreeManualExchangeBackend()
else:
backend = InvenTreeFixerExchangeBackend()
# Update rates # Update rates
backend.update_rates() backend.update_rates()
+3
View File
@@ -41,6 +41,7 @@ from .views import IndexView, SearchView, DatabaseStatsView
from .views import SettingsView, EditUserView, SetPasswordView from .views import SettingsView, EditUserView, SetPasswordView
from .views import AppearanceSelectView, SettingCategorySelectView from .views import AppearanceSelectView, SettingCategorySelectView
from .views import DynamicJsView from .views import DynamicJsView
from .views import ExchangeRatesView
from common.views import SettingEdit from common.views import SettingEdit
@@ -90,6 +91,8 @@ settings_urls = [
url(r'^build/?', SettingsView.as_view(template_name='InvenTree/settings/build.html'), name='settings-build'), url(r'^build/?', SettingsView.as_view(template_name='InvenTree/settings/build.html'), name='settings-build'),
url(r'^purchase-order/?', SettingsView.as_view(template_name='InvenTree/settings/po.html'), name='settings-po'), url(r'^purchase-order/?', SettingsView.as_view(template_name='InvenTree/settings/po.html'), name='settings-po'),
url(r'^sales-order/?', SettingsView.as_view(template_name='InvenTree/settings/so.html'), name='settings-so'), url(r'^sales-order/?', SettingsView.as_view(template_name='InvenTree/settings/so.html'), name='settings-so'),
url(r'^currencies/?', SettingsView.as_view(template_name='InvenTree/settings/currencies.html'), name='settings-currencies'),
url(r'^echange-rates/?', ExchangeRatesView.as_view(), name='refresh-exchange-rates'),
url(r'^(?P<pk>\d+)/edit/', SettingEdit.as_view(), name='setting-edit'), url(r'^(?P<pk>\d+)/edit/', SettingEdit.as_view(), name='setting-edit'),
+15
View File
@@ -27,6 +27,7 @@ from users.models import check_user_role, RuleSet
from .forms import DeleteForm, EditUserForm, SetPasswordForm from .forms import DeleteForm, EditUserForm, SetPasswordForm
from .forms import ColorThemeSelectForm, SettingCategorySelectForm from .forms import ColorThemeSelectForm, SettingCategorySelectForm
from .helpers import str2bool from .helpers import str2bool
from .tasks import update_exchange_rates
from rest_framework import views from rest_framework import views
@@ -908,3 +909,17 @@ class DatabaseStatsView(AjaxView):
""" """
return ctx return ctx
class ExchangeRatesView(SettingsView):
success_url = reverse_lazy('settings-currencies')
def post(self, request, *args, **kwargs):
# Process exchange rates
update_exchange_rates()
# TODO: Update context
return HttpResponseRedirect(self.success_url)
@@ -0,0 +1,43 @@
{% extends "InvenTree/settings/settings.html" %}
{% load i18n %}
{% load inventree_extras %}
{% block tabs %}
{% include "InvenTree/settings/tabs.html" with tab='currencies' %}
{% endblock %}
{% block subtitle %}
{% trans "Currency Settings" %}
{% endblock %}
{% block settings %}
<table class='table table-striped table-condensed'>
{% include "InvenTree/settings/header.html" %}
<tbody>
{% include "InvenTree/settings/setting.html" with key="INVENTREE_DEFAULT_CURRENCY" icon="fa-dollar-sign" %}
{% include "InvenTree/settings/setting.html" with key="INVENTREE_FIXER_API_KEY" icon="fa-key" %}
</tbody>
</table>
<div class='row'>
<div class='col-sm-6'>
<h4>{% trans "Exchange Rates" %}</h4>
</div>
</div>
<table class='table table-striped table-condensed' id='exchange-rates'>
</table>
<form action="{% url 'refresh-exchange-rates' %}" method="post">
{% csrf_token %}
<button type="submit" class='btn btn-primary'>{% trans "Refresh Exchange Rates" %}</button>
</form>
{% endblock %}
{% block js_ready %}
{{ block.super }}
{% comment %} TODO: Update exchange-rates table! {% endcomment %}
{% comment %} Or do it using context instead of JS? {% endcomment %}
{% endblock %}
@@ -19,8 +19,6 @@
{% include "InvenTree/settings/setting.html" with key="INVENTREE_INSTANCE_TITLE" icon="fa-info-circle" %} {% include "InvenTree/settings/setting.html" with key="INVENTREE_INSTANCE_TITLE" icon="fa-info-circle" %}
{% include "InvenTree/settings/setting.html" with key="INVENTREE_BASE_URL" icon="fa-globe" %} {% include "InvenTree/settings/setting.html" with key="INVENTREE_BASE_URL" icon="fa-globe" %}
{% include "InvenTree/settings/setting.html" with key="INVENTREE_COMPANY_NAME" icon="fa-building" %} {% include "InvenTree/settings/setting.html" with key="INVENTREE_COMPANY_NAME" icon="fa-building" %}
{% include "InvenTree/settings/setting.html" with key="INVENTREE_DEFAULT_CURRENCY" icon="fa-dollar-sign" %}
{% include "InvenTree/settings/setting.html" with key="INVENTREE_FIXER_API_KEY" icon="fa-key" %}
{% include "InvenTree/settings/setting.html" with key="INVENTREE_DOWNLOAD_FROM_URL" icon="fa-cloud-download-alt" %} {% include "InvenTree/settings/setting.html" with key="INVENTREE_DOWNLOAD_FROM_URL" icon="fa-cloud-download-alt" %}
</tbody> </tbody>
</table> </table>
@@ -36,5 +36,8 @@
<li {% if tab == 'so' %} class='active'{% endif %}> <li {% if tab == 'so' %} class='active'{% endif %}>
<a href="{% url 'settings-so' %}"><span class='fas fa-truck'></span> {% trans "Sales Orders" %}</a> <a href="{% url 'settings-so' %}"><span class='fas fa-truck'></span> {% trans "Sales Orders" %}</a>
</li> </li>
<li {% if tab == 'currencies' %} class='active'{% endif %}>
<a href="{% url 'settings-currencies' %}"><span class='fas fa-dollar-sign'></span> {% trans "Currencies" %}</a>
</li>
</ul> </ul>
{% endif %} {% endif %}