Adds expense approval workflow
Implements expense approval functionality, allowing superusers to review and approve or reject expense entries. This includes: - Filtering account balance calculations and user balance calculations to only include cleared journal entries. - Adding API endpoints to retrieve pending expense entries and approve/reject them. - Updating the UI to display pending expenses to superusers and provide actions to approve or reject them. This ensures better control over expenses within the system.
This commit is contained in:
parent
8221feec20
commit
018a074915
4 changed files with 232 additions and 8 deletions
22
crud.py
22
crud.py
|
|
@ -313,14 +313,17 @@ async def get_journal_entries_by_user(
|
|||
|
||||
|
||||
async def get_account_balance(account_id: str) -> int:
|
||||
"""Calculate account balance (debits - credits for assets/expenses, credits - debits for liabilities/equity/revenue)"""
|
||||
"""Calculate account balance (debits - credits for assets/expenses, credits - debits for liabilities/equity/revenue)
|
||||
Only includes entries that are cleared (flag='*'), excludes pending/flagged/voided entries."""
|
||||
result = await db.fetchone(
|
||||
"""
|
||||
SELECT
|
||||
COALESCE(SUM(debit), 0) as total_debit,
|
||||
COALESCE(SUM(credit), 0) as total_credit
|
||||
FROM entry_lines
|
||||
WHERE account_id = :id
|
||||
COALESCE(SUM(el.debit), 0) as total_debit,
|
||||
COALESCE(SUM(el.credit), 0) as total_credit
|
||||
FROM entry_lines el
|
||||
JOIN journal_entries je ON el.journal_entry_id = je.id
|
||||
WHERE el.account_id = :id
|
||||
AND je.flag = '*'
|
||||
""",
|
||||
{"id": account_id},
|
||||
)
|
||||
|
|
@ -360,8 +363,15 @@ async def get_user_balance(user_id: str) -> UserBalance:
|
|||
balance = await get_account_balance(account.id)
|
||||
|
||||
# Get all entry lines for this account to calculate fiat balances
|
||||
# Only include cleared entries (exclude pending/flagged/voided)
|
||||
entry_lines = await db.fetchall(
|
||||
"SELECT * FROM entry_lines WHERE account_id = :account_id",
|
||||
"""
|
||||
SELECT el.*
|
||||
FROM entry_lines el
|
||||
JOIN journal_entries je ON el.journal_entry_id = je.id
|
||||
WHERE el.account_id = :account_id
|
||||
AND je.flag = '*'
|
||||
""",
|
||||
{"account_id": account.id},
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue