Verified Commit 3259814c authored by Jakob Moser's avatar Jakob Moser
Browse files

Add Person#deposit method

parent de015c10
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
from __future__ import annotations

from typing import TYPE_CHECKING, Literal
from typing import TYPE_CHECKING, Literal, Self

from babel.numbers import format_currency
from sqlalchemy.orm import Mapped, mapped_column, relationship
@@ -87,6 +87,20 @@ class Person(Base):
        amount_cents = int(to_be_paid)
        self.balance_cents -= amount_cents

    def deposit(self, to_be_deposited: int | IntLike) -> None:
        """
        Deposit something, adding its value (in cents) to the current balance.

        >>> p = Person(name="Luca", cl_account_name="mustermensch")
        >>> p.balance_cents
        0
        >>> p.deposit(500)
        >>> p.balance_cents
        500
        """
        amount_cents = int(to_be_deposited)
        self.balance_cents += amount_cents

    def __str__(self) -> str:
        """
        Convert the person to a human-readable string representation:
@@ -108,3 +122,13 @@ class Person(Base):
            "balance_str": self.balance_str,
            "balance_cents": self.balance_cents,
        }

    @classmethod
    def get_by_full_name(cls, full_name: str) -> Self | None:
        """
        Try to find the person matching the given full name (leniently, e.g., Umlauts
        are ignored).

        If no persons can be found or there are too many plausible matches, None is returned.
        """
        raise NotImplementedError()