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

Serialize to JSON

parent c92193d3
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
from pathlib import Path
from decimal import Decimal
import sys
import json

from tabulate import tabulate

@@ -13,7 +14,8 @@ sums = PaymentOrderCollection(directory).sums_by_budgetary_item_id
# print(sums)

budget_plan = load_pdf(sys.argv[2])
#print(budget_plan)
with open("instance/budget_plan.json", "w") as f:
    json.dump(budget_plan.as_dict, f, indent=4, ensure_ascii=False)


def _format_as_euro_de(amount: Decimal) -> str:
+5 −1
Original line number Diff line number Diff line
from dataclasses import dataclass
from typing import Self
from typing import Self, Any
from collections.abc import Iterable, Sequence

from .BudgetaryItem import BudgetaryItem
@@ -28,3 +28,7 @@ class BudgetPlan:

    def item(self, id: str) -> BudgetaryItem:
        pass  # TODO

    @property
    def as_dict(self) -> dict[str, Any]:
        return {"groups": [group.as_dict for group in self.groups]}
+10 −1
Original line number Diff line number Diff line
from dataclasses import dataclass
from typing import Self
from typing import Self, Any
from collections.abc import Iterable, Sequence

from ..cash_flow.CashFlowDirection import CashFlowDirection
@@ -49,3 +49,12 @@ class BudgetaryGroup:

    def item(self, id: str) -> BudgetaryItem:
        return self._items[id]

    @property
    def as_dict(self) -> dict[str, Any]:
        return {
            "id": self.id,
            "name": self.name,
            "cashFlowDirection": self.cash_flow_direction.value,
            "items": [item.as_dict for item in self.items],
        }
+4 −0
Original line number Diff line number Diff line
@@ -15,3 +15,7 @@ class BudgetaryItem:
    id: str
    name: str
    amount: Decimal

    @property
    def as_dict(self) -> dict[str, str]:
        return {"id": self.id, "name": self.name, "amount": str(self.amount)}