Verified Commit de1879d9 authored by Jakob Moser's avatar Jakob Moser
Browse files

Add rudimentary support for budget plans

parent 929ffd40
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
from dataclasses import dataclass

from .BudgetaryItem import BudgetaryItem


@dataclass(frozen=True, eq=False)
class BudgetPlan:

    items: dict[str, BudgetaryItem]
+24 −0
Original line number Diff line number Diff line
import csv
from pathlib import Path
from typing import Sequence


from .BudgetPlan import BudgetPlan
from .BudgetaryItem import BudgetaryItem
from ..amount.AmountParser import parse_euro_amount


def _is_budgetary_item_row(row: Sequence[str]) -> bool:
    return len(row) >= 3 and row[0] and row[1] and row[2]


def load_csv(csv_path: Path | str) -> BudgetPlan:
    with open(csv_path, newline="") as f:
        reader = csv.reader(f)
        items = [
            BudgetaryItem(id=row[0], name=row[1], amount=parse_euro_amount(row[2]))
            for row in reader
            if _is_budgetary_item_row(row)
        ]

    return BudgetPlan({item.id: item for item in items})
+15 −0
Original line number Diff line number Diff line
from dataclasses import dataclass
from decimal import Decimal


@dataclass(frozen=True, eq=False)
class BudgetaryItem:
    """Entry in a budget plan.

    Has an id, a name and an amount, e.g.,
    740.0208, Projekte und Veranstaltungen kultureller Art, 550.00 €
    """

    id: str
    name: str
    amount: Decimal
+0 −0

Empty file added.