Skip to content

Commit

Permalink
Merge pull request #15 from Engenere/imp-simples-nacional
Browse files Browse the repository at this point in the history
DANFE: Melhoria para o Simples Nacional
  • Loading branch information
antoniospneto authored May 6, 2024
2 parents 28938ea + 7bed69e commit 838d134
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Here is a breakdown of all the configuration options available in ``DanfeConfig`
config.tax_configuration = TaxConfiguration.WITHOUT_IPI
```
- **Default**: ``STANDARD_ICMS_IPI``
- **WARNING: This feature is not yet implemented.**

6. **Invoice Display**
- **Type**: ``InvoiceDisplay`` (Enum)
Expand Down
18 changes: 15 additions & 3 deletions brazilfiscalreport/danfe/danfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(self, xml, config: DanfeConfig = None):
self.det = root.findall(f"{URL}det")
self.inf_adic = root.find(f"{URL}infAdic")
self.issqn_tot = root.find(f"{URL}ISSQNtot")
self.crt = extract_text(self.emit, "CRT")

self.total_receipt_height = 19 # TODO need compute

Expand Down Expand Up @@ -309,7 +310,12 @@ def _get_products_info(self):

# merge 'origem' with 'CST' of ICMS.
orig = extract_text(el_imp_ICMS, "orig")
cst = extract_text(el_imp_ICMS, "CST")
if self.crt == "1":
# Regime Simples Nacional
cst = extract_text(el_imp_ICMS, "CSOSN")
else:
# Regime Normal
cst = extract_text(el_imp_ICMS, "CST")
o_cst = orig + cst

product = ProductInfo(
Expand Down Expand Up @@ -1212,11 +1218,17 @@ def _draw_products(self, height_product_table, products, additional_data=""):
description="DADOS DO PRODUTO / SERVIÇO",
pdf=self,
).render()
cst_label = "CST"
cst_width = 6
if self.crt == "1":
# Regime Simples Nacional
cst_label = "CSOSN"
cst_width = 8
colunas = [
"CÓDIGO",
"DESCRIÇÃO DOS PRODUTOS / SERVIÇOS",
"NCM/SH",
"CST",
cst_label,
"CFOP",
"UN.",
"QTD.",
Expand All @@ -1232,7 +1244,7 @@ def _draw_products(self, height_product_table, products, additional_data=""):
"%IPI",
]
monetary_fields_index = [6, 7, 8, 9, 10, 11, 12, 13]
col_widths = (15, None, 11, 6, 7, 6, 12, 13, 13, 13, 10, 10, 9, 8)
col_widths = (15, None, 11, cst_width, 7, 6, 12, 13, 13, 13, 10, 10, 9, 8)
defined_width = sum(filter(None, col_widths))
none_width = self.edw - defined_width
fixed_col_widths = tuple(w if w is not None else none_width for w in col_widths)
Expand Down
181 changes: 181 additions & 0 deletions tests/fixtures/nfe_test_sn.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<?xml version="1.0" encoding="UTF-8"?>
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<infNFe versao="4.00" Id="NFe35200159594315000157550010000000022062777169">
<ide>
<cUF>35</cUF>
<cNF>06277716</cNF>
<natOp>Venda</natOp>
<mod>55</mod>
<serie>1</serie>
<nNF>2</nNF>
<dhEmi>2020-01-01T12:00:00+01:00</dhEmi>
<dhSaiEnt>2020-01-01T12:00:00+01:00</dhSaiEnt>
<tpNF>1</tpNF>
<idDest>1</idDest>
<cMunFG>3550308</cMunFG>
<tpImp>1</tpImp>
<tpEmis>1</tpEmis>
<cDV>9</cDV>
<tpAmb>2</tpAmb>
<finNFe>1</finNFe>
<indFinal>1</indFinal>
<indPres>0</indPres>
<procEmi>0</procEmi>
<verProc>Odoo Brasil OCA v14</verProc>
</ide>
<emit>
<CNPJ>81583054000129</CNPJ>
<xNome>Empresa Simples Nacional Ltda</xNome>
<xFant>Empresa Simples Nacional</xFant>
<enderEmit>
<xLgr>Avenida Paulista</xLgr>
<nro>1</nro>
<xBairro>Bela Vista</xBairro>
<cMun>3550308</cMun>
<xMun>São Paulo</xMun>
<UF>SP</UF>
<CEP>01311000</CEP>
<cPais>1058</cPais>
<xPais>Brasil</xPais>
<fone>5511999999999</fone>
</enderEmit>
<IE>078016350838</IE>
<CRT>1</CRT>
</emit>
<dest>
<CPF>76586507812</CPF>
<xNome>NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL</xNome>
<enderDest>
<xLgr>Rua do Bosque</xLgr>
<nro>238</nro>
<xBairro>Barra Funda</xBairro>
<cMun>3550308</cMun>
<xMun>São Paulo</xMun>
<UF>SP</UF>
<CEP>01136000</CEP>
<cPais>1058</cPais>
<xPais>Brasil</xPais>
<fone>1138817417</fone>
</enderDest>
<indIEDest>1</indIEDest>
<email>[email protected]</email>
</dest>
<det nItem="1">
<prod>
<cProd>FC4566120</cProd>
<cEAN>SEM GTIN</cEAN>
<xProd>Frango Congelado Inteiro - Aves selecionadas de alta qualidade, embaladas individualmente</xProd>
<NCM>02071200</NCM>
<CFOP>5101</CFOP>
<uCom>KG</uCom>
<qCom>207.8000</qCom>
<vUnCom>13.3700000000</vUnCom>
<vProd>2778.29</vProd>
<cEANTrib>SEM GTIN</cEANTrib>
<uTrib>KG</uTrib>
<qTrib>207.8000</qTrib>
<vUnTrib>13.3700000000</vUnTrib>
<indTot>1</indTot>
</prod>
<imposto>
<vTotTrib>978.24</vTotTrib>
<ICMS>
<ICMSSN101>
<orig>0</orig>
<CSOSN>101</CSOSN>
<pCredSN>3.2000</pCredSN>
<vCredICMSSN>88.91</vCredICMSSN>
</ICMSSN101>
</ICMS>
<IPI>
<cEnq>999</cEnq>
<IPITrib>
<CST>99</CST>
<vBC>0.00</vBC>
<pIPI>0.0000</pIPI>
<vIPI>0.00</vIPI>
</IPITrib>
</IPI>
<PIS>
<PISOutr>
<CST>49</CST>
<vBC>0.00</vBC>
<pPIS>0.0000</pPIS>
<vPIS>0.00</vPIS>
</PISOutr>
</PIS>
<COFINS>
<COFINSOutr>
<CST>49</CST>
<vBC>0.00</vBC>
<pCOFINS>0.0000</pCOFINS>
<vCOFINS>0.00</vCOFINS>
</COFINSOutr>
</COFINS>
</imposto>
</det>
<total>
<ICMSTot>
<vBC>0.00</vBC>
<vICMS>0.00</vICMS>
<vICMSDeson>0.00</vICMSDeson>
<vFCP>0.00</vFCP>
<vBCST>0.00</vBCST>
<vST>0.00</vST>
<vFCPST>0.00</vFCPST>
<vFCPSTRet>0.00</vFCPSTRet>
<vProd>2778.29</vProd>
<vFrete>0.00</vFrete>
<vSeg>0.00</vSeg>
<vDesc>0.00</vDesc>
<vII>0.00</vII>
<vIPI>0.00</vIPI>
<vIPIDevol>0.00</vIPIDevol>
<vPIS>0.00</vPIS>
<vCOFINS>0.00</vCOFINS>
<vOutro>0.00</vOutro>
<vNF>2778.29</vNF>
<vTotTrib>978.24</vTotTrib>
</ICMSTot>
</total>
<transp>
<modFrete>9</modFrete>
<vol>
<qVol>13</qVol>
<esp>volumes</esp>
<pesoL>207.800</pesoL>
<pesoB>207.800</pesoB>
</vol>
</transp>
<cobr>
<fat>
<nFat>11556</nFat>
<vOrig>2778.29</vOrig>
<vLiq>2778.29</vLiq>
</fat>
<dup>
<nDup>001</nDup>
<dVenc>2024-05-30</dVenc>
<vDup>1433.60</vDup>
</dup>
<dup>
<nDup>002</nDup>
<dVenc>2024-06-16</dVenc>
<vDup>1433.60</vDup>
</dup>
</cobr>
<pag>
<detPag>
<indPag>1</indPag>
<tPag>15</tPag>
<vPag>2778.29</vPag>
</detPag>
</pag>
<infAdic>
<infAdFisco>SIMPLES NACIONAL - Documento emitido por ME ou EPP optante pelo simples
nacional, nao gera direito a credito fiscal de IPI. Permite o aproveitamento do
credito de ICMS, no valor de R$ 88,91, correspondente a aliquota de3,20%, nos termos
do artigo 23 da LC 123/2006.</infAdFisco>
</infAdic>
</infNFe>
</NFe>
Binary file added tests/generated/danfe/danfe_sn.pdf
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/test_danfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ def test_danfe_default(tmp_path, load_danfe):
assert_pdf_equal(danfe, pdf_path, tmp_path)


def test_danfe_sn(tmp_path, load_danfe):
"""
Tests the creation of a DANFE for an Electronic Invoice (NF-e) issued by a company
opting for the Simples Nacional regime.
"""
danfe = load_danfe("nfe_test_sn.xml")
pdf_path = get_pdf_output_path("danfe", "danfe_sn")
assert_pdf_equal(danfe, pdf_path, tmp_path)


def test_danfe_minimal(tmp_path, load_danfe):
minimal_config = DanfeConfig(
margins=Margins(top=8, right=8, bottom=8, left=8),
Expand Down

0 comments on commit 838d134

Please sign in to comment.