mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-10 22:34:11 +02:00
brmbar.Currency: Fix exception handling, Account.name is an attribute
This commit is contained in:
parent
3f45f52f60
commit
e738ca2b84
1 changed files with 5 additions and 5 deletions
|
@ -46,14 +46,14 @@ class Currency:
|
|||
raise NameError("Something fishy in find_buy_rate.");
|
||||
buy = res[0]
|
||||
if buy < 0:
|
||||
raise NameError("Currency.rate(): Unknown conversion " + other.name() + " to " + self.name())
|
||||
raise NameError("Currency.rate(): Unknown conversion " + other.name + " to " + self.name)
|
||||
# sell rate
|
||||
res = self.db.execute_and_fetch("SELECT public.find_sell_rate(%s, %s)",[self.id, other.id])
|
||||
if res is None:
|
||||
raise NameError("Something fishy in find_sell_rate.");
|
||||
sell = res[0]
|
||||
if sell < 0:
|
||||
raise NameError("Currency.rate(): Unknown conversion " + self.name() + " to " + other.name())
|
||||
raise NameError("Currency.rate(): Unknown conversion " + self.name + " to " + other.name)
|
||||
|
||||
return (buy, sell)
|
||||
|
||||
|
@ -61,13 +61,13 @@ class Currency:
|
|||
# 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())
|
||||
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())
|
||||
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
|
||||
|
||||
|
@ -77,7 +77,7 @@ class Currency:
|
|||
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())
|
||||
raise NameError("Currency.convert(): Unknown conversion " + self.name + " to " + target.name)
|
||||
rate, rate_dir = res
|
||||
if rate_dir == "source_to_target":
|
||||
resamount = amount * rate
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue