Verified Commit 306b163f authored by Jakob Moser's avatar Jakob Moser
Browse files

Implement missing function

parent 04602984
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -43,7 +43,17 @@ class BudgetPlan:
        return [item for group in self.groups for item in group.items]

    def item(self, id: str) -> BudgetaryItem:
        pass  # TODO
        matching_items = [item for item in self.items if item.id == id]

        match len(matching_items):
            case 0:
                raise KeyError(f"No budgetary item with id = {id}")
            case 1:
                return matching_items[0]
            case _:
                raise RuntimeError(
                    f"There were more than 1 budgetary item with the same id, this should not happen"
                )

    @property
    def as_dict(self) -> dict[str, Any]: