diff --git a/liberapay/billing/transactions.py b/liberapay/billing/transactions.py index 616c4c620b..4e538cd23c 100644 --- a/liberapay/billing/transactions.py +++ b/liberapay/billing/transactions.py @@ -382,8 +382,9 @@ def propagate_exchange(cursor, participant, exchange, error, amount): AND b.ts < now() - INTERVAL %s AND b.disputed IS NOT TRUE AND b.locked_for IS NULL + AND b.amount::currency = %s ORDER BY b.owner = e.participant DESC, b.ts - """, (participant.id, QUARANTINE)) + """, (participant.id, QUARANTINE, amount.currency)) withdrawable = sum(b.amount for b in bundles) x = -amount if x > withdrawable: diff --git a/liberapay/models/__init__.py b/liberapay/models/__init__.py index daeb2e7370..53c1576c13 100644 --- a/liberapay/models/__init__.py +++ b/liberapay/models/__init__.py @@ -183,6 +183,7 @@ def _check_bundles_grouped_by_withdrawal_against_exchanges(cursor): LEFT JOIN ( SELECT b.withdrawal, sum(b.amount) as withdrawn FROM cash_bundles b + WHERE b.withdrawal IS NOT NULL GROUP BY b.withdrawal ) AS b ON b.withdrawal = e.id ) diff --git a/liberapay/models/participant.py b/liberapay/models/participant.py index d1930df6fa..6efa65ed87 100644 --- a/liberapay/models/participant.py +++ b/liberapay/models/participant.py @@ -59,6 +59,7 @@ NS, deserialize, erase_cookie, serialize, set_cookie, emails, i18n, markdown, ) +from liberapay.utils.currencies import MoneyBasket from liberapay.website import website @@ -1065,8 +1066,8 @@ def get_current_wallet(self, currency=None, create=False): from liberapay.billing.transactions import create_wallet return create_wallet(self.db, self, currency) - def get_current_wallets(self): - return self.db.all(""" + def get_current_wallets(self, cursor=None): + return (cursor or self.db).all(""" SELECT * FROM wallets WHERE owner = %s @@ -1082,6 +1083,14 @@ def get_balance_in(self, currency): AND is_current """, (self.id, currency)) or ZERO[currency] + def get_balances(self): + return self.db.one(""" + SELECT basket_sum(balance) + FROM wallets + WHERE owner = %s + AND is_current + """, (self.id,)) or MoneyBasket() + # Events # ====== @@ -1552,7 +1561,7 @@ def update_giving(self, cursor=None): ORDER BY p2.join_time IS NULL, t.ctime ASC """, (self.id,)) updated = [] - for wallet in self.get_current_wallets(): + for wallet in self.get_current_wallets(cursor): fake_balance = wallet.balance currency = fake_balance.currency fake_balance += self.get_receiving_in(currency, cursor) diff --git a/liberapay/utils/currencies.py b/liberapay/utils/currencies.py index 1d5c062155..66da2c1a34 100644 --- a/liberapay/utils/currencies.py +++ b/liberapay/utils/currencies.py @@ -90,6 +90,10 @@ def __bool__(self): __nonzero__ = __bool__ + @property + def currencies_present(self): + return [m.currency for m in self if m.amount] + @classmethod def sum(cls, amounts): r = cls(Money('0.00', 'EUR'), usd=Money('0.00', 'USD')) diff --git a/liberapay/utils/i18n.py b/liberapay/utils/i18n.py index 5f8b45545c..c37dec2d7f 100644 --- a/liberapay/utils/i18n.py +++ b/liberapay/utils/i18n.py @@ -76,7 +76,7 @@ def format_decimal(self, *a): return format_decimal(*a, locale=self) def format_money_basket(self, basket): - return ', '.join( + return ' + '.join( format_currency(money.amount, money.currency, locale=self) for money in basket if money ) or '0' diff --git a/www/%username/settings/close.spt b/www/%username/settings/close.spt index 306ef4796e..05f7d8181a 100644 --- a/www/%username/settings/close.spt +++ b/www/%username/settings/close.spt @@ -25,6 +25,8 @@ pending_payouts = website.db.one(""" AND status = 'created' """, (participant.id,)) +balances = participant.get_balances() + title = _("Close Account") subhead = participant.username @@ -60,22 +62,17 @@ subhead = participant.username
{{ _("You have {0} in your wallet. What should we do with it?", - participant.balance) }}
- + balances) }}{{ _( "If neither option works for you, please contact support@liberapay.com." ) }}
diff --git a/www/%username/tip.spt b/www/%username/tip.spt index afc1214074..1da435b61e 100644 --- a/www/%username/tip.spt +++ b/www/%username/tip.spt @@ -71,7 +71,10 @@ if request.method == 'POST': back_to += '&' if '?' in back_to else '?' back_to += 'success=' + b64encode_s(out["msg"]) if out['amount'] and not out['is_funded'] and not out['is_pledge']: - response.redirect('/' + tipper.username + '/wallet/payin/' + b64encode_s(back_to)) + response.redirect( + '/' + tipper.username + '/wallet/payin/' + b64encode_s(back_to) + + '?currency=' + currency + ) response.redirect(back_to, trusted_url=False) else: out = tipper.get_tip_to(tippee) diff --git a/www/%username/wallet/index.html.spt b/www/%username/wallet/index.html.spt index 862180d078..7cd6e09f5b 100644 --- a/www/%username/wallet/index.html.spt +++ b/www/%username/wallet/index.html.spt @@ -186,11 +186,15 @@ else: locale.format_money_basket(event['balances']) }}