forked from brmlab/brmbar-github
Currency.py: remove unused methods - rates2, convert
This commit is contained in:
parent
92deae6775
commit
f6128ecc4a
1 changed files with 0 additions and 51 deletions
|
|
@ -67,57 +67,6 @@ class Currency:
|
||||||
|
|
||||||
return (buy, sell)
|
return (buy, sell)
|
||||||
|
|
||||||
def rates2(self, other):
|
|
||||||
# the original code for compare testing
|
|
||||||
res = self.db.execute_and_fetch(
|
|
||||||
"SELECT rate, rate_dir FROM exchange_rates WHERE target = %s AND source = %s AND valid_since <= NOW() ORDER BY valid_since DESC LIMIT 1",
|
|
||||||
[self.id, other.id],
|
|
||||||
)
|
|
||||||
if res is None:
|
|
||||||
raise NameError(
|
|
||||||
"Currency.rate(): Unknown conversion "
|
|
||||||
+ other.name()
|
|
||||||
+ " to "
|
|
||||||
+ self.name()
|
|
||||||
)
|
|
||||||
buy_rate, buy_rate_dir = res
|
|
||||||
buy = buy_rate if buy_rate_dir == "target_to_source" else 1 / buy_rate
|
|
||||||
|
|
||||||
res = self.db.execute_and_fetch(
|
|
||||||
"SELECT rate, rate_dir FROM exchange_rates WHERE target = %s AND source = %s AND valid_since <= NOW() ORDER BY valid_since DESC LIMIT 1",
|
|
||||||
[other.id, self.id],
|
|
||||||
)
|
|
||||||
if res is None:
|
|
||||||
raise NameError(
|
|
||||||
"Currency.rate(): Unknown conversion "
|
|
||||||
+ self.name()
|
|
||||||
+ " to "
|
|
||||||
+ other.name()
|
|
||||||
)
|
|
||||||
sell_rate, sell_rate_dir = res
|
|
||||||
sell = sell_rate if sell_rate_dir == "source_to_target" else 1 / sell_rate
|
|
||||||
|
|
||||||
return (buy, sell)
|
|
||||||
|
|
||||||
def convert(self, amount, target):
|
|
||||||
res = self.db.execute_and_fetch(
|
|
||||||
"SELECT rate, rate_dir FROM exchange_rates WHERE target = %s AND source = %s AND valid_since <= NOW() ORDER BY valid_since DESC LIMIT 1",
|
|
||||||
[target.id, self.id],
|
|
||||||
)
|
|
||||||
if res is None:
|
|
||||||
raise NameError(
|
|
||||||
"Currency.convert(): Unknown conversion "
|
|
||||||
+ self.name()
|
|
||||||
+ " to "
|
|
||||||
+ target.name()
|
|
||||||
)
|
|
||||||
rate, rate_dir = res
|
|
||||||
if rate_dir == "source_to_target":
|
|
||||||
resamount = amount * rate
|
|
||||||
else:
|
|
||||||
resamount = amount / rate
|
|
||||||
return resamount
|
|
||||||
|
|
||||||
def str(self, amount):
|
def str(self, amount):
|
||||||
return "{:.2f} {}".format(amount, self.name)
|
return "{:.2f} {}".format(amount, self.name)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue