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
|
pass
|
||||||
|
|
||||||
return {}
|
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.ExchangeRateHostBackend'
|
||||||
|
|
||||||
EXCHANGE_BACKEND = 'InvenTree.exchange.' + CONFIG.get('exchange_backend', 'InvenTreeManualExchangeBackend')
|
|
||||||
|
|
||||||
# Extract email settings from the config file
|
# Extract email settings from the config file
|
||||||
email_config = CONFIG.get('email', {})
|
email_config = CONFIG.get('email', {})
|
||||||
|
@ -163,20 +163,27 @@ def check_for_updates():
|
|||||||
|
|
||||||
def update_exchange_rates():
|
def update_exchange_rates():
|
||||||
"""
|
"""
|
||||||
Update backend rates
|
If an API key for fixer.io has been provided, attempt to update currency exchange rates
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from .exchange import get_exchange_rate_backend
|
import common.models
|
||||||
|
from django.conf import settings
|
||||||
|
from InvenTree.exchange import ExchangeRateHostBackend
|
||||||
except AppRegistryNotReady:
|
except AppRegistryNotReady:
|
||||||
# Apps not yet loaded!
|
# Apps not yet loaded!
|
||||||
return
|
return
|
||||||
|
|
||||||
# Get exchange rate backend
|
backend = ExchangeRateHostBackend()
|
||||||
backend = get_exchange_rate_backend()
|
print(f"Updating exchange rates from {backend.url}")
|
||||||
|
|
||||||
# Update rates
|
currencies = ','.join(settings.CURRENCIES)
|
||||||
backend.update_rates(base_currency=backend.base_currency)
|
|
||||||
|
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):
|
def send_email(subject, body, recipients, from_email=None):
|
||||||
|
@ -10,8 +10,15 @@ import common.models
|
|||||||
|
|
||||||
INVENTREE_SW_VERSION = "0.2.2 pre"
|
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():
|
def inventreeInstanceName():
|
||||||
|
@ -87,12 +87,6 @@ class InvenTreeSetting(models.Model):
|
|||||||
'choices': djmoney.settings.CURRENCY_CHOICES,
|
'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': {
|
'INVENTREE_DOWNLOAD_FROM_URL': {
|
||||||
'name': _('Download from URL'),
|
'name': _('Download from URL'),
|
||||||
'description': _('Allow download of remote images and files from external URL'),
|
'description': _('Allow download of remote images and files from external URL'),
|
||||||
|
@ -119,6 +119,12 @@ def inventree_version(*args, **kwargs):
|
|||||||
return version.inventreeVersion()
|
return version.inventreeVersion()
|
||||||
|
|
||||||
|
|
||||||
|
@register.simple_tag()
|
||||||
|
def inventree_api_version(*args, **kwargs):
|
||||||
|
""" Return InvenTree API version """
|
||||||
|
return version.inventreeApiVersion()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def django_version(*args, **kwargs):
|
def django_version(*args, **kwargs):
|
||||||
""" Return Django version string """
|
""" Return Django version string """
|
||||||
|
@ -29,6 +29,11 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</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>
|
<tr>
|
||||||
<td><span class='fas fa-hashtag'></span></td>
|
<td><span class='fas fa-hashtag'></span></td>
|
||||||
<td>{% trans "Django Version" %}</td>
|
<td>{% trans "Django Version" %}</td>
|
||||||
|
@ -41,9 +41,10 @@ LABEL org.label-schema.schema-version="1.0" \
|
|||||||
|
|
||||||
# Create user account
|
# Create user account
|
||||||
RUN addgroup -S inventreegroup && adduser -S inventree -G inventreegroup
|
RUN addgroup -S inventreegroup && adduser -S inventree -G inventreegroup
|
||||||
|
|
||||||
WORKDIR ${INVENTREE_HOME}
|
WORKDIR ${INVENTREE_HOME}
|
||||||
|
|
||||||
RUN mkdir ${INVENTREE_STATIC_ROOT}
|
RUN mkdir -p ${INVENTREE_STATIC_ROOT}
|
||||||
|
|
||||||
# Install required system packages
|
# Install required system packages
|
||||||
RUN apk add --no-cache git make bash \
|
RUN apk add --no-cache git make bash \
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
# Create required directory structure (if it does not already exist)
|
# Create required directory structure (if it does not already exist)
|
||||||
if [[ ! -d "$INVENTREE_STATIC_ROOT" ]]; then
|
if [[ ! -d "$INVENTREE_STATIC_ROOT" ]]; then
|
||||||
echo "Creating directory $INVENTREE_STATIC_ROOT"
|
echo "Creating directory $INVENTREE_STATIC_ROOT"
|
||||||
mkdir $INVENTREE_STATIC_ROOT
|
mkdir -p $INVENTREE_STATIC_ROOT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -d "$INVENTREE_MEDIA_ROOT" ]]; then
|
if [[ ! -d "$INVENTREE_MEDIA_ROOT" ]]; then
|
||||||
echo "Creating directory $INVENTREE_MEDIA_ROOT"
|
echo "Creating directory $INVENTREE_MEDIA_ROOT"
|
||||||
mkdir $INVENTREE_MEDIA_ROOT
|
mkdir -p $INVENTREE_MEDIA_ROOT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if "config.yaml" has been copied into the correct location
|
# 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)
|
# Create required directory structure (if it does not already exist)
|
||||||
if [[ ! -d "$INVENTREE_STATIC_ROOT" ]]; then
|
if [[ ! -d "$INVENTREE_STATIC_ROOT" ]]; then
|
||||||
echo "Creating directory $INVENTREE_STATIC_ROOT"
|
echo "Creating directory $INVENTREE_STATIC_ROOT"
|
||||||
mkdir $INVENTREE_STATIC_ROOT
|
mkdir -p $INVENTREE_STATIC_ROOT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -d "$INVENTREE_MEDIA_ROOT" ]]; then
|
if [[ ! -d "$INVENTREE_MEDIA_ROOT" ]]; then
|
||||||
echo "Creating directory $INVENTREE_MEDIA_ROOT"
|
echo "Creating directory $INVENTREE_MEDIA_ROOT"
|
||||||
mkdir $INVENTREE_MEDIA_ROOT
|
mkdir -p $INVENTREE_MEDIA_ROOT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if "config.yaml" has been copied into the correct location
|
# Check if "config.yaml" has been copied into the correct location
|
||||||
|
Loading…
Reference in New Issue
Block a user