dodil/erp-brick-timesheets

DODIL ERP brick: timesheets

src/brick_timesheets/domain/money.py

"""Money is an exact Decimal carried to two places (NUMERIC(18,2)); a rate and an hour carry four (NUMERIC(19,4)). Never a float."""
from decimal import ROUND_HALF_UP, Decimal

CENT = Decimal("0.01")
FOURTH = Decimal("0.0001")
ZERO = Decimal("0.00")


def money(v) -> Decimal:
    return Decimal(str(v)).quantize(CENT, rounding=ROUND_HALF_UP)


def hours4(v) -> Decimal:
    return Decimal(str(v)).quantize(FOURTH, rounding=ROUND_HALF_UP)