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.
29 lines
760 B
Python
29 lines
760 B
Python
import asyncio
|
|
|
|
from fastapi import APIRouter
|
|
from loguru import logger
|
|
|
|
from .crud import db
|
|
from .tasks import wait_for_paid_invoices
|
|
from .views import castle_generic_router
|
|
from .views_api import castle_api_router
|
|
|
|
castle_ext: APIRouter = APIRouter(prefix="/castle", tags=["Castle"])
|
|
castle_ext.include_router(castle_generic_router)
|
|
castle_ext.include_router(castle_api_router)
|
|
|
|
castle_static_files = [
|
|
{
|
|
"path": "/castle/static",
|
|
"name": "castle_static",
|
|
}
|
|
]
|
|
|
|
|
|
def castle_start():
|
|
"""Initialize Castle extension background tasks"""
|
|
logger.info("Starting Castle accounting extension background tasks")
|
|
asyncio.create_task(wait_for_paid_invoices())
|
|
|
|
|
|
__all__ = ["castle_ext", "castle_static_files", "db", "castle_start"]
|