Adds background task for invoice processing

Implements a background task that listens for paid invoices
and automatically records them in the accounting system. This
ensures payments are captured even if the user closes their
browser before the client-side polling detects the payment.

Introduces a new `get_journal_entry_by_reference` function to
improve idempotency when recording payments.
This commit is contained in:
padreug 2025-11-02 01:40:40 +01:00
parent 4957826c49
commit cfa25cc61b
4 changed files with 142 additions and 2 deletions

14
crud.py
View file

@ -226,6 +226,20 @@ async def get_journal_entry(entry_id: str) -> Optional[JournalEntry]:
return entry
async def get_journal_entry_by_reference(reference: str) -> Optional[JournalEntry]:
"""Get a journal entry by its reference field (e.g., payment_hash)"""
entry = await db.fetchone(
"SELECT * FROM journal_entries WHERE reference = :reference",
{"reference": reference},
JournalEntry,
)
if entry:
entry.lines = await get_entry_lines(entry.id)
return entry
async def get_entry_lines(journal_entry_id: str) -> list[EntryLine]:
rows = await db.fetchall(
"SELECT * FROM entry_lines WHERE journal_entry_id = :id",