mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merged @SchrodingersGat ExchangeRateHost integration work
This commit is contained in:
commit
654d4ecf46
@ -135,3 +135,18 @@ class InvenTreeFixerExchangeBackend(InvenTreeManualExchangeBackend):
|
||||
pass
|
||||
|
||||
return {}
|
||||
|
||||
|
||||
class ExchangeRateHostBackend(SimpleExchangeBackend):
|
||||
"""
|
||||
Backend for https://exchangerate.host/
|
||||
"""
|
||||
|
||||
name = "exchangerate.host"
|
||||
|
||||
def __init__(self):
|
||||
self.url = "https://api.exchangerate.host/latest"
|
||||
|
||||
def get_params(self):
|
||||
# No API key is required
|
||||
return {}
|
||||
|
@ -513,9 +513,7 @@ CURRENCIES = CONFIG.get(
|
||||
],
|
||||
)
|
||||
|
||||
BASE_CURRENCY = CONFIG.get('base_currency', 'USD')
|
||||
|
||||
EXCHANGE_BACKEND = 'InvenTree.exchange.' + CONFIG.get('exchange_backend', 'InvenTreeManualExchangeBackend')
|
||||
EXCHANGE_BACKEND = 'InvenTree.exchange.ExchangeRateHostBackend'
|
||||
|
||||
# Extract email settings from the config file
|
||||
email_config = CONFIG.get('email', {})
|
||||
|
@ -163,20 +163,27 @@ def check_for_updates():
|
||||
|
||||
def update_exchange_rates():
|
||||
"""
|
||||
Update backend rates
|
||||
If an API key for fixer.io has been provided, attempt to update currency exchange rates
|
||||
"""
|
||||
|
||||
try:
|
||||
from .exchange import get_exchange_rate_backend
|
||||
import common.models
|
||||
from django.conf import settings
|
||||
from InvenTree.exchange import ExchangeRateHostBackend
|
||||
except AppRegistryNotReady:
|
||||
# Apps not yet loaded!
|
||||
return
|
||||
|
||||
# Get exchange rate backend
|
||||
backend = get_exchange_rate_backend()
|
||||
|
||||
# Update rates
|
||||
backend.update_rates(base_currency=backend.base_currency)
|
||||
backend = ExchangeRateHostBackend()
|
||||
print(f"Updating exchange rates from {backend.url}")
|
||||
|
||||
currencies = ','.join(settings.CURRENCIES)
|
||||
|
||||
base = common.models.InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY')
|
||||
|
||||
print(f"Using base currency '{base}'")
|
||||
|
||||
backend.update_rates(base_currency=base, symbols=currencies)
|
||||
|
||||
|
||||
def send_email(subject, body, recipients, from_email=None):
|
||||
|
@ -10,8 +10,15 @@ import common.models
|
||||
|
||||
INVENTREE_SW_VERSION = "0.2.2 pre"
|
||||
|
||||
# Increment this number whenever there is a significant change to the API that any clients need to know about
|
||||
INVENTREE_API_VERSION = 2
|
||||
"""
|
||||
Increment thi API version number whenever there is a significant change to the API that any clients need to know about
|
||||
|
||||
v3 -> 2021-05-22:
|
||||
- The updated StockItem "history tracking" now uses a different interface
|
||||
|
||||
"""
|
||||
|
||||
INVENTREE_API_VERSION = 3
|
||||
|
||||
|
||||
def inventreeInstanceName():
|
||||
|
@ -87,12 +87,6 @@ class InvenTreeSetting(models.Model):
|
||||
'choices': djmoney.settings.CURRENCY_CHOICES,
|
||||
},
|
||||
|
||||
'INVENTREE_FIXER_API_KEY': {
|
||||
'name': _('fixer.io API key'),
|
||||
'description': _('API key for fixer.io currency conversion service'),
|
||||
'default': '',
|
||||
},
|
||||
|
||||
'INVENTREE_DOWNLOAD_FROM_URL': {
|
||||
'name': _('Download from URL'),
|
||||
'description': _('Allow download of remote images and files from external URL'),
|
||||
|
@ -119,6 +119,12 @@ def inventree_version(*args, **kwargs):
|
||||
return version.inventreeVersion()
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def inventree_api_version(*args, **kwargs):
|
||||
""" Return InvenTree API version """
|
||||
return version.inventreeApiVersion()
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def django_version(*args, **kwargs):
|
||||
""" Return Django version string """
|
||||
|
@ -31,4 +31,4 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
@ -29,6 +29,11 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><span class='fas fa-code'></span></td>
|
||||
<td>{% trans "API Version" %}</td>
|
||||
<td>{% inventree_api_version %}{% include "clip.html" %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><span class='fas fa-hashtag'></span></td>
|
||||
<td>{% trans "Django Version" %}</td>
|
||||
|
@ -41,9 +41,10 @@ LABEL org.label-schema.schema-version="1.0" \
|
||||
|
||||
# Create user account
|
||||
RUN addgroup -S inventreegroup && adduser -S inventree -G inventreegroup
|
||||
|
||||
WORKDIR ${INVENTREE_HOME}
|
||||
|
||||
RUN mkdir ${INVENTREE_STATIC_ROOT}
|
||||
RUN mkdir -p ${INVENTREE_STATIC_ROOT}
|
||||
|
||||
# Install required system packages
|
||||
RUN apk add --no-cache git make bash \
|
||||
|
@ -3,12 +3,12 @@
|
||||
# Create required directory structure (if it does not already exist)
|
||||
if [[ ! -d "$INVENTREE_STATIC_ROOT" ]]; then
|
||||
echo "Creating directory $INVENTREE_STATIC_ROOT"
|
||||
mkdir $INVENTREE_STATIC_ROOT
|
||||
mkdir -p $INVENTREE_STATIC_ROOT
|
||||
fi
|
||||
|
||||
if [[ ! -d "$INVENTREE_MEDIA_ROOT" ]]; then
|
||||
echo "Creating directory $INVENTREE_MEDIA_ROOT"
|
||||
mkdir $INVENTREE_MEDIA_ROOT
|
||||
mkdir -p $INVENTREE_MEDIA_ROOT
|
||||
fi
|
||||
|
||||
# Check if "config.yaml" has been copied into the correct location
|
||||
|
@ -3,12 +3,12 @@
|
||||
# Create required directory structure (if it does not already exist)
|
||||
if [[ ! -d "$INVENTREE_STATIC_ROOT" ]]; then
|
||||
echo "Creating directory $INVENTREE_STATIC_ROOT"
|
||||
mkdir $INVENTREE_STATIC_ROOT
|
||||
mkdir -p $INVENTREE_STATIC_ROOT
|
||||
fi
|
||||
|
||||
if [[ ! -d "$INVENTREE_MEDIA_ROOT" ]]; then
|
||||
echo "Creating directory $INVENTREE_MEDIA_ROOT"
|
||||
mkdir $INVENTREE_MEDIA_ROOT
|
||||
mkdir -p $INVENTREE_MEDIA_ROOT
|
||||
fi
|
||||
|
||||
# Check if "config.yaml" has been copied into the correct location
|
||||
|
Loading…
Reference in New Issue
Block a user