mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-06 13:01:50 +02:00
rename default to no_currency
default was obvious within the class itself, but not in other places
This commit is contained in:
parent
8a6160ff57
commit
6095f29910
4 changed files with 13 additions and 13 deletions
|
@ -13,7 +13,7 @@ class Singleton(type):
|
||||||
|
|
||||||
class CurrencyConverter(object, metaclass=Singleton):
|
class CurrencyConverter(object, metaclass=Singleton):
|
||||||
# Get exchange rates
|
# Get exchange rates
|
||||||
default = "XXX"
|
no_currency = "XXX"
|
||||||
api_url = "https://api.exchangeratesapi.io/latest?base=USD"
|
api_url = "https://api.exchangeratesapi.io/latest?base=USD"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -22,19 +22,19 @@ class CurrencyConverter(object, metaclass=Singleton):
|
||||||
@cached(cache=TTLCache(maxsize=1, ttl=86400))
|
@cached(cache=TTLCache(maxsize=1, ttl=86400))
|
||||||
def get_rates(self):
|
def get_rates(self):
|
||||||
rates = requests.get(self.api_url).json()["rates"]
|
rates = requests.get(self.api_url).json()["rates"]
|
||||||
rates[self.default] = 1.0
|
rates[self.no_currency] = 1.0
|
||||||
return rates
|
return rates
|
||||||
|
|
||||||
def get_currencies(self):
|
def get_currencies(self):
|
||||||
rates = [rate for rate in self.get_rates()]
|
rates = [rate for rate in self.get_rates()]
|
||||||
rates.sort(key=lambda rate: "" if rate == self.default else rate)
|
rates.sort(key=lambda rate: "" if rate == self.no_currency else rate)
|
||||||
return rates
|
return rates
|
||||||
|
|
||||||
def exchange_currency(self, amount, source_currency, dest_currency):
|
def exchange_currency(self, amount, source_currency, dest_currency):
|
||||||
if (
|
if (
|
||||||
source_currency == dest_currency
|
source_currency == dest_currency
|
||||||
or source_currency == self.default
|
or source_currency == self.no_currency
|
||||||
or dest_currency == self.default
|
or dest_currency == self.no_currency
|
||||||
):
|
):
|
||||||
return amount
|
return amount
|
||||||
|
|
||||||
|
|
|
@ -47,11 +47,11 @@ def get_billform_for(project, set_default=True, **kwargs):
|
||||||
if form.original_currency.data == "None":
|
if form.original_currency.data == "None":
|
||||||
form.original_currency.data = project.default_currency
|
form.original_currency.data = project.default_currency
|
||||||
|
|
||||||
if form.original_currency.data != CurrencyConverter.default:
|
if form.original_currency.data != CurrencyConverter.no_currency:
|
||||||
form.original_currency.choices.remove(
|
form.original_currency.choices.remove(
|
||||||
(
|
(
|
||||||
CurrencyConverter.default,
|
CurrencyConverter.no_currency,
|
||||||
render_localized_currency(CurrencyConverter.default, detailed=False),
|
render_localized_currency(CurrencyConverter.no_currency, detailed=False),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ class BillForm(FlaskForm):
|
||||||
bill.external_link = ""
|
bill.external_link = ""
|
||||||
bill.date = self.date
|
bill.date = self.date
|
||||||
bill.owers = [Person.query.get(ower, project) for ower in self.payed_for]
|
bill.owers = [Person.query.get(ower, project) for ower in self.payed_for]
|
||||||
bill.original_currency = CurrencyConverter.default
|
bill.original_currency = CurrencyConverter.no_currency
|
||||||
bill.converted_amount = self.currency_helper.exchange_currency(
|
bill.converted_amount = self.currency_helper.exchange_currency(
|
||||||
bill.amount, bill.original_currency, project.default_currency
|
bill.amount, bill.original_currency, project.default_currency
|
||||||
)
|
)
|
||||||
|
|
|
@ -23,7 +23,7 @@ def upgrade():
|
||||||
sa.Column(
|
sa.Column(
|
||||||
"original_currency",
|
"original_currency",
|
||||||
sa.String(length=3),
|
sa.String(length=3),
|
||||||
server_default=CurrencyConverter.default,
|
server_default=CurrencyConverter.no_currency,
|
||||||
nullable=True,
|
nullable=True,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -42,7 +42,7 @@ def upgrade():
|
||||||
sa.Column(
|
sa.Column(
|
||||||
"default_currency",
|
"default_currency",
|
||||||
sa.String(length=3),
|
sa.String(length=3),
|
||||||
server_default=CurrencyConverter.default,
|
server_default=CurrencyConverter.no_currency,
|
||||||
nullable=True,
|
nullable=True,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -393,10 +393,10 @@ def edit_project():
|
||||||
if edit_form.validate_on_submit():
|
if edit_form.validate_on_submit():
|
||||||
project = edit_form.update(g.project)
|
project = edit_form.update(g.project)
|
||||||
# Update converted currency
|
# Update converted currency
|
||||||
if project.default_currency != CurrencyConverter.default:
|
if project.default_currency != CurrencyConverter.no_currency:
|
||||||
for bill in project.get_bills():
|
for bill in project.get_bills():
|
||||||
|
|
||||||
if bill.original_currency == CurrencyConverter.default:
|
if bill.original_currency == CurrencyConverter.no_currency:
|
||||||
bill.original_currency = project.default_currency
|
bill.original_currency = project.default_currency
|
||||||
|
|
||||||
bill.converted_amount = CurrencyConverter().exchange_currency(
|
bill.converted_amount = CurrencyConverter().exchange_currency(
|
||||||
|
|
Loading…
Reference in a new issue