2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 12:05:53 +00:00

Simplify exhange rate backend

This commit is contained in:
Oliver Walters
2021-05-27 15:45:38 +10:00
parent 62320e46d5
commit af1904b6e4
10 changed files with 47 additions and 134 deletions

View File

@ -13,6 +13,8 @@ from djmoney.forms.fields import MoneyField
from InvenTree.forms import HelperForm
from InvenTree.helpers import clean_decimal
from common.settings import currency_code_default
from .files import FileManager
from .models import InvenTreeSetting
@ -182,7 +184,7 @@ class MatchItem(forms.Form):
if 'price' in col_guess.lower():
self.fields[field_name] = MoneyField(
label=_(col_guess),
default_currency=InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY'),
default_currency=currency_code_default(),
decimal_places=5,
max_digits=19,
required=False,

View File

@ -19,6 +19,8 @@ from djmoney.models.fields import MoneyField
from djmoney.contrib.exchange.models import convert_money
from djmoney.contrib.exchange.exceptions import MissingRate
from common.settings import currency_code_default
from django.utils.translation import ugettext_lazy as _
from django.core.validators import MinValueValidator, URLValidator
from django.core.exceptions import ValidationError
@ -80,20 +82,6 @@ class InvenTreeSetting(models.Model):
'default': '',
},
'INVENTREE_DEFAULT_CURRENCY': {
'name': _('Default Currency'),
'description': _('Default currency'),
'default': 'USD',
'choices': djmoney.settings.CURRENCY_CHOICES,
},
'CUSTOM_EXCHANGE_RATES': {
'name': _('Custom Exchange Rates'),
'description': _('Enable custom exchange rates'),
'validator': bool,
'default': False,
},
'INVENTREE_DOWNLOAD_FROM_URL': {
'name': _('Download from URL'),
'description': _('Allow download of remote images and files from external URL'),
@ -766,7 +754,7 @@ def get_price(instance, quantity, moq=True, multiples=True, currency=None):
if currency is None:
# Default currency selection
currency = InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY')
currency = currency_code_default()
pb_min = None
for pb in instance.price_breaks.all():

View File

@ -7,7 +7,8 @@ from __future__ import unicode_literals
from moneyed import CURRENCIES
from common.models import InvenTreeSetting
import common.models
from django.conf import settings
def currency_code_default():
@ -15,7 +16,7 @@ def currency_code_default():
Returns the default currency code (or USD if not specified)
"""
code = InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY')
code = settings.BASE_CURRENCY
if code not in CURRENCIES:
code = 'USD'
@ -28,4 +29,4 @@ def stock_expiry_enabled():
Returns True if the stock expiry feature is enabled
"""
return InvenTreeSetting.get_setting('STOCK_ENABLE_EXPIRY')
return common.models.InvenTreeSetting.get_setting('STOCK_ENABLE_EXPIRY')