Copies the 6 pure fiscal modules (domains, chave_acesso, tpag, presets, resolver, xml_builder) from sowai-auto's backend/app/modules/fiscal/ into this standalone lib, with only the two mechanical changes required to drop the app.* dependency: import prefix rename, and TaxRule (ORM) -> TaxRuleLike (structural Protocol) in the resolver. No other line changes -- byte-level parity with the auto is the point. Ports the pure test suites (domains, chave_acesso, resolver with a local FakeTaxRule satisfying TaxRuleLike, xml_builder) plus a new test_presets_data covering the PRESETS dict directly (the auto's equivalent test exercises the apply-preset HTTP/DB flow, which isn't part of the extracted pure core). 55 tests pass locally via `uv run pytest`, no Postgres/k8s required.
70 lines
2.6 KiB
Python
70 lines
2.6 KiB
Python
"""Presets fiscais seed-editáveis: teste PURO do dict `PRESETS` (dados,
|
|
não a API `/tax-profiles/apply-preset/*` -- aquela é do produto, DB/HTTP,
|
|
não faz parte do núcleo puro extraído). Os valores REAIS vieram do iCode
|
|
da Thiago (perfis "Padrão" cód 110 e "Óleos/ST" cód 108) -- estes testes
|
|
travam o contrato de dados que o consumidor (auto) usa para semear
|
|
`TaxRule`/`TaxProfile`."""
|
|
from decimal import Decimal
|
|
|
|
from sowai_fiscal.presets import PRESETS, FiscalPreset, PresetRule
|
|
|
|
|
|
def test_presets_catalog_has_the_two_icode_profiles():
|
|
assert {"autopecas_simples_padrao", "autopecas_simples_st"} <= PRESETS.keys()
|
|
|
|
|
|
def test_padrao_preset_has_venda_and_devolucao_icms_rules():
|
|
preset = PRESETS["autopecas_simples_padrao"]
|
|
assert isinstance(preset, FiscalPreset)
|
|
assert preset.regime_alvo == "1"
|
|
|
|
icms_rules = [r for r in preset.rules if r.tax_domain == "icms"]
|
|
assert len(icms_rules) == 2
|
|
|
|
venda = next(r for r in icms_rules if r.tipo_operacao == "venda")
|
|
assert venda.csosn == "102"
|
|
assert venda.cfop == "5102"
|
|
assert venda.aliquota == Decimal("0")
|
|
|
|
devolucao = next(r for r in icms_rules if r.tipo_operacao == "devolucao")
|
|
assert devolucao.csosn == "102"
|
|
assert devolucao.cfop == "1202"
|
|
|
|
|
|
def test_padrao_preset_pis_cofins_cst_08():
|
|
preset = PRESETS["autopecas_simples_padrao"]
|
|
pis = next(r for r in preset.rules if r.tax_domain == "pis")
|
|
cofins = next(r for r in preset.rules if r.tax_domain == "cofins")
|
|
assert pis.cst == "08"
|
|
assert cofins.cst == "08"
|
|
assert pis.aliquota == Decimal("0")
|
|
assert cofins.aliquota == Decimal("0")
|
|
|
|
|
|
def test_st_preset_has_venda_and_devolucao_icmsst_rules():
|
|
preset = PRESETS["autopecas_simples_st"]
|
|
icmsst_rules = [r for r in preset.rules if r.tax_domain == "icmsst"]
|
|
assert len(icmsst_rules) == 2
|
|
|
|
venda = next(r for r in icmsst_rules if r.tipo_operacao == "venda")
|
|
assert venda.csosn == "500"
|
|
assert venda.cfop == "5405"
|
|
|
|
devolucao = next(r for r in icmsst_rules if r.tipo_operacao == "devolucao")
|
|
assert devolucao.csosn == "500"
|
|
assert devolucao.cfop == "1202"
|
|
|
|
|
|
def test_st_preset_pis_cofins_cst_04_monofasico():
|
|
preset = PRESETS["autopecas_simples_st"]
|
|
pis = next(r for r in preset.rules if r.tax_domain == "pis")
|
|
cofins = next(r for r in preset.rules if r.tax_domain == "cofins")
|
|
assert pis.cst == "04"
|
|
assert cofins.cst == "04"
|
|
|
|
|
|
def test_no_preset_rule_carries_origem():
|
|
# NENHUM preset carrega `origem`: origem é sempre do Part (review do
|
|
# frontend, 2026-07-14) -- `PresetRule` não tem sequer o campo.
|
|
assert not hasattr(PresetRule(tax_domain="icms"), "origem")
|