"""Canonical :class:`~decimal.Decimal` money primitives.Single authoritative implementation of the half-up euro-centrounding convention used across every AEAT calculation surface(LIRPF art. 23.1 rental net income, IRPF deductions, IVA prorata,asset depreciation, inventory cost basis). Callers in``aeat.domain.*`` import :func:`round_to_cents` and the ``CENT`` quantumfrom here rather than reimplementing the quantize call.The half-up rounding mode (:data:`~decimal.ROUND_HALF_UP`) matchesthe AEAT publication convention: a residual cent of exactly 0.5rounds away from zero. Python's default banker's rounding(``ROUND_HALF_EVEN``) does NOT match AEAT and must never be used atthe euro-cent boundary for any operator-facing or filed value."""from__future__importannotationsfromdecimalimportROUND_HALF_UP,DecimalCENT=Decimal("0.01")
[docs]defround_to_cents(value:Decimal)->Decimal:"""Round *value* to euro-cent precision with half-up semantics. Args: value: The :class:`~decimal.Decimal` amount to round. Returns: A :class:`~decimal.Decimal` quantised to two fractional digits using :data:`decimal.ROUND_HALF_UP`. """returnvalue.quantize(CENT,rounding=ROUND_HALF_UP)