from central.app.field_contract import ALREADY, CHANGE, MANUAL, NA, sped_pis_cofins_match from central.tests.test_field_contract import CO1, CO3, EV, decision, product, run, st UNUSED = {**CO1, "pis_cofins_unused_by_emission": True} def test_sped_table_lookup_is_prefix_based_and_active_only(): hits = sped_pis_cofins_match("10063021") assert hits and {h[1] for h in hits} == {"06"} and hits[0][0] == "4.3.13" assert sped_pis_cofins_match("99999999") == [] def test_simples_pis_cofins_written_only_from_official_table_and_never_assumed_zero(): r = run(p=product(CLASSIFICACAO_FISCAL="10063021"), co=UNUSED) assert st(r, "COD_SAIDA_PIS") == (CHANGE, "06") and st(r, "COD_SAIDA_COFINS") == (CHANGE, "06") assert r["ALIQ_PIS"]["state"] == NA and r["COD_ENTRADA_PIS"]["state"] == NA plain = run(co=UNUSED) # NCM without any SPED special regime: SGV does not consume the field, nothing is invented assert all(plain[f]["state"] == NA and plain[f]["proposed"] is None for f in ("COD_SAIDA_PIS", "ALIQ_PIS", "COD_ENTRADA_COFINS")) assert run(co=CO1)["COD_SAIDA_PIS"]["state"] == MANUAL # without emission evidence the company question remains assert run(co={**CO3, "pis_cofins_unused_by_emission": True})["COD_SAIDA_PIS"]["state"] == MANUAL # evidence only relaxes CRT 1 def test_cfop_never_contradicts_the_erp_st_declaration(): r = run(p=product(CFOP="5405", CSOSN="500", CST="060", SITUACAO_TRIBUTARIA="T")) assert r["CFOP"]["state"] != CHANGE or r["CFOP"]["proposed"] != "5102" def test_kitchen_flag_alone_and_cst_digit_never_prove_role_or_origin(): r = run(p=product(PROD_COZINHA=1, COD_ORIGEM_MERCADORIA=None, CST="040")) assert r["COD_ORIGEM_MERCADORIA"]["state"] == MANUAL and r["COD_ORIGEM_MERCADORIA"]["reason"] == "ORIGIN_NO_EVIDENCE" assert r["IPPT"]["proposed"] != "P" or r["IPPT"]["state"] != CHANGE def test_store_ipi_profile_is_a_company_decision_never_defaulted(): undecided = run(ipi_profile=None) assert undecided["IPI"]["state"] == MANUAL and undecided["IPI"]["input_key"] == "store_ipi_profile" assert run(ipi_profile={"scope": "COMPANY", "scope_key": "", "key": "store_ipi_profile", "value": "LEAVE_NOT_APPLICABLE"})["IPI"]["state"] == NA assert run()["IPI"]["state"] == CHANGE # POPULATE_REFERENCE_RATE keeps the TIPI rule