| """Calculadoras de tributos brasileiros.""" |
| from __future__ import annotations |
|
|
| from dataclasses import dataclass |
| from decimal import Decimal, ROUND_HALF_UP |
|
|
|
|
| def arred(valor: Decimal, casas: int = 2) -> Decimal: |
| quantizador = Decimal(10) ** -casas |
| return valor.quantize(quantizador, rounding=ROUND_HALF_UP) |
|
|
|
|
| @dataclass |
| class ResultadoCalculo: |
| base_calculo: Decimal |
| aliquota: Decimal |
| valor_tributo: Decimal |
| deducoes: Decimal = Decimal("0") |
| creditos: Decimal = Decimal("0") |
| valor_a_recolher: Decimal = Decimal("0") |
| detalhes: dict = None |
|
|
| def __post_init__(self): |
| if self.detalhes is None: |
| self.detalhes = {} |
| if self.valor_a_recolher == Decimal("0"): |
| self.valor_a_recolher = max( |
| Decimal("0"), self.valor_tributo - self.creditos - self.deducoes |
| ) |
|
|