mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2024-11-19 01:43:42 +01:00
fix: balances view on use non deleted wallets (#2385)
* fix: balances view on use non deleted wallets closes #2224 * fixup! fix: balances view on use non deleted wallets --------- Co-authored-by: Pavol Rusnak <pavol@rusnak.io>
This commit is contained in:
parent
bbfc301440
commit
782cbfc77f
@ -587,11 +587,6 @@ async def get_total_balance(conn: Optional[Connection] = None):
|
|||||||
return 0 if row[0] is None else row[0]
|
return 0 if row[0] is None else row[0]
|
||||||
|
|
||||||
|
|
||||||
async def get_active_wallet_total_balance(conn: Optional[Connection] = None):
|
|
||||||
row = await (conn or db).fetchone("SELECT SUM(balance) FROM balances")
|
|
||||||
return 0 if row[0] is None else row[0]
|
|
||||||
|
|
||||||
|
|
||||||
# wallet payments
|
# wallet payments
|
||||||
# ---------------
|
# ---------------
|
||||||
|
|
||||||
|
@ -471,3 +471,23 @@ async def m017_add_timestamp_columns_to_accounts_and_wallets(db):
|
|||||||
except OperationalError as exc:
|
except OperationalError as exc:
|
||||||
logger.error(f"Migration 17 failed: {exc}")
|
logger.error(f"Migration 17 failed: {exc}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
async def m018_balances_view_exclude_deleted(db):
|
||||||
|
"""
|
||||||
|
Make deleted wallets not show up in the balances view.
|
||||||
|
"""
|
||||||
|
await db.execute("DROP VIEW balances")
|
||||||
|
await db.execute(
|
||||||
|
"""
|
||||||
|
CREATE VIEW balances AS
|
||||||
|
SELECT apipayments.wallet,
|
||||||
|
SUM(apipayments.amount - ABS(apipayments.fee)) AS balance
|
||||||
|
FROM apipayments
|
||||||
|
LEFT JOIN wallets ON apipayments.wallet = wallets.id
|
||||||
|
WHERE (wallets.deleted = false OR wallets.deleted is NULL)
|
||||||
|
AND ((apipayments.pending = false AND apipayments.amount > 0)
|
||||||
|
OR apipayments.amount < 0)
|
||||||
|
GROUP BY wallet
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user