50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
import json
|
|
from pathlib import Path
|
|
|
|
from central.app.fiscal_completeness import evaluate_field, evaluate_product, load_requiredness_matrix
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
def test_requiredness_matrix_covers_contract_fields_once():
|
|
contract = json.loads((ROOT / "docs/FISCAL_FIELD_CONTRACT_V1.json").read_text(encoding="utf-8"))
|
|
matrix = load_requiredness_matrix(ROOT / "docs/FISCAL_REQUIREDNESS_MATRIX_V1.json")
|
|
|
|
assert set(matrix["fields"]) == set(contract["fields"])
|
|
assert len(matrix["fields"]) == 23
|
|
assert set(matrix["classifications"]) == {
|
|
"REQUIRED", "CONDITIONAL", "OPTIONAL_REFERENCE", "NOT_APPLICABLE", "ERP_NOT_USED"
|
|
}
|
|
|
|
|
|
def test_conditional_empty_when_not_triggered_is_not_missing():
|
|
matrix = load_requiredness_matrix(ROOT / "docs/FISCAL_REQUIREDNESS_MATRIX_V1.json")
|
|
|
|
result = evaluate_field("IPI", None, {"contribuinte_ipi": "N", "has_numeric_tipi": False}, matrix)
|
|
|
|
assert result["status"] == "CONDITIONAL_NOT_TRIGGERED"
|
|
assert result["valid"] is True
|
|
|
|
|
|
def test_required_missing_makes_product_incomplete():
|
|
matrix = load_requiredness_matrix(ROOT / "docs/FISCAL_REQUIREDNESS_MATRIX_V1.json")
|
|
|
|
result = evaluate_product(
|
|
{"CLASSIFICACAO_FISCAL": None, "CFOP": "5102"},
|
|
{"product_role": "RESALE", "operation": "SALE"},
|
|
matrix,
|
|
)
|
|
|
|
assert result["FISCALLY_COMPLETE"] is False
|
|
assert result["fields"]["CLASSIFICACAO_FISCAL"]["status"] == "REQUIRED_MISSING"
|
|
|
|
|
|
def test_erp_not_used_is_not_missing():
|
|
matrix = load_requiredness_matrix(ROOT / "docs/FISCAL_REQUIREDNESS_MATRIX_V1.json")
|
|
|
|
result = evaluate_field("IAT", None, {"erp_uses_iat": False}, matrix)
|
|
|
|
assert result["status"] == "ERP_NOT_SUPPORTED"
|
|
assert result["valid"] is True
|