mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-11-29 20:02:51 +01:00
Provider registry modeled after automatic exchange rates: each provider declares its own settings fields, rendered dynamically in the service form. Lunch Flow is the first provider. - Map provider accounts to WYGIWYH accounts with a start date and an optional currency filter - Hourly task syncs due services; manual sync from the list - Deduplicates through Transaction.internal_id, optionally matching transactions already entered by hand - Per account errors and provider reported connection problems Refs #498
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
from abc import ABC, abstractmethod
|
|
from dataclasses import dataclass
|
|
from datetime import date
|
|
from decimal import Decimal
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class RemoteAccount:
|
|
id: str
|
|
name: str
|
|
# Currency codes as the provider spells them
|
|
currencies: tuple = ()
|
|
# Why the account can't be synced right now (expired connection...), empty if fine
|
|
error: str = ""
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class RemoteTransaction:
|
|
id: str
|
|
date: date
|
|
# Signed: negative is money leaving the account
|
|
amount: Decimal
|
|
description: str = ""
|
|
notes: str = ""
|
|
currency: str = ""
|
|
|
|
|
|
class BankSyncProvider(ABC):
|
|
"""A bank data aggregator.
|
|
|
|
``settings_fields`` declares the provider's own configuration as Django form
|
|
fields. The service form renders them when the provider is selected and the
|
|
values end up in ``BankSyncService.settings`` under the same keys.
|
|
"""
|
|
|
|
settings_fields: dict = {}
|
|
|
|
def __init__(self, settings: dict):
|
|
self.settings = settings or {}
|
|
|
|
@abstractmethod
|
|
def list_accounts(self) -> list[RemoteAccount]:
|
|
"""Every account the credentials can see."""
|
|
|
|
@abstractmethod
|
|
def get_transactions(
|
|
self, account_id: str, start_date: date
|
|
) -> list[RemoteTransaction]:
|
|
"""Posted transactions of ``account_id`` dated ``start_date`` or later."""
|