Improves super user balance and journal views
For super users, the balance view now displays the net position (liabilities - receivables) of the Castle. The journal view shows all entries across all users. The settings are now loaded first to determine if the user is a super user.
This commit is contained in:
parent
d7b5259b74
commit
3a26d963dc
2 changed files with 22 additions and 9 deletions
|
|
@ -551,12 +551,13 @@ window.app = Vue.createApp({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async created() {
|
async created() {
|
||||||
|
// Load settings first to determine if user is super user
|
||||||
|
await this.loadSettings()
|
||||||
|
await this.loadUserWallet()
|
||||||
await this.loadBalance()
|
await this.loadBalance()
|
||||||
await this.loadTransactions()
|
await this.loadTransactions()
|
||||||
await this.loadAccounts()
|
await this.loadAccounts()
|
||||||
await this.loadCurrencies()
|
await this.loadCurrencies()
|
||||||
await this.loadSettings()
|
|
||||||
await this.loadUserWallet()
|
|
||||||
// Load users if super user (for receivable dialog)
|
// Load users if super user (for receivable dialog)
|
||||||
if (this.isSuperUser) {
|
if (this.isSuperUser) {
|
||||||
await this.loadUsers()
|
await this.loadUsers()
|
||||||
|
|
|
||||||
26
views_api.py
26
views_api.py
|
|
@ -158,6 +158,12 @@ async def api_get_user_entries(
|
||||||
limit: int = 100,
|
limit: int = 100,
|
||||||
) -> list[JournalEntry]:
|
) -> list[JournalEntry]:
|
||||||
"""Get journal entries that affect the current user's accounts"""
|
"""Get journal entries that affect the current user's accounts"""
|
||||||
|
from lnbits.settings import settings as lnbits_settings
|
||||||
|
|
||||||
|
# If super user, show all journal entries
|
||||||
|
if wallet.wallet.user == lnbits_settings.super_user:
|
||||||
|
return await get_all_journal_entries(limit)
|
||||||
|
|
||||||
return await get_journal_entries_by_user(wallet.wallet.user, limit)
|
return await get_journal_entries_by_user(wallet.wallet.user, limit)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -416,10 +422,17 @@ async def api_get_my_balance(
|
||||||
"""Get current user's balance with the Castle"""
|
"""Get current user's balance with the Castle"""
|
||||||
from lnbits.settings import settings as lnbits_settings
|
from lnbits.settings import settings as lnbits_settings
|
||||||
|
|
||||||
# If super user, show total castle liabilities (what castle owes to all users)
|
# If super user, show total castle position
|
||||||
if wallet.wallet.user == lnbits_settings.super_user:
|
if wallet.wallet.user == lnbits_settings.super_user:
|
||||||
all_balances = await get_all_user_balances()
|
all_balances = await get_all_user_balances()
|
||||||
total_owed = sum(b.balance for b in all_balances if b.balance > 0)
|
|
||||||
|
# Calculate total:
|
||||||
|
# Positive balances = Castle owes users (liabilities)
|
||||||
|
# Negative balances = Users owe Castle (receivables)
|
||||||
|
# Net: positive means castle owes, negative means castle is owed
|
||||||
|
total_liabilities = sum(b.balance for b in all_balances if b.balance > 0)
|
||||||
|
total_receivables = sum(abs(b.balance) for b in all_balances if b.balance < 0)
|
||||||
|
net_balance = total_liabilities - total_receivables
|
||||||
|
|
||||||
# Aggregate fiat balances from all users
|
# Aggregate fiat balances from all users
|
||||||
total_fiat_balances = {}
|
total_fiat_balances = {}
|
||||||
|
|
@ -427,14 +440,13 @@ async def api_get_my_balance(
|
||||||
for currency, amount in user_balance.fiat_balances.items():
|
for currency, amount in user_balance.fiat_balances.items():
|
||||||
if currency not in total_fiat_balances:
|
if currency not in total_fiat_balances:
|
||||||
total_fiat_balances[currency] = 0.0
|
total_fiat_balances[currency] = 0.0
|
||||||
# Only add positive balances (what castle owes)
|
# Add all balances (positive and negative)
|
||||||
if amount > 0:
|
total_fiat_balances[currency] += amount
|
||||||
total_fiat_balances[currency] += amount
|
|
||||||
|
|
||||||
# Return as castle's "balance" - positive means castle owes money
|
# Return net position
|
||||||
return UserBalance(
|
return UserBalance(
|
||||||
user_id=wallet.wallet.user,
|
user_id=wallet.wallet.user,
|
||||||
balance=total_owed,
|
balance=net_balance,
|
||||||
accounts=[],
|
accounts=[],
|
||||||
fiat_balances=total_fiat_balances,
|
fiat_balances=total_fiat_balances,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue