diff --git a/README.md b/README.md index d16772c..6c4854b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ Biblioteca Python que tem por objetivo enviar NFe, NFCe e NFSe no Brasil [![Coverage Status](https://coveralls.io/repos/danimaribeiro/PyTrustNFe/badge.svg?branch=master)](https://coveralls.io/r/danimaribeiro/PyTrustNFe?branch=master) -[![Code Health](https://landscape.io/github/danimaribeiro/PyTrustNFe/master/landscape.svg?style=flat)](https://landscape.io/github/danimaribeiro/PyTrustNFe/master) [![Build Status](https://travis-ci.org/danimaribeiro/PyTrustNFe.svg?branch=master)](https://travis-ci.org/danimaribeiro/PyTrustNFe) [![PyPI version](https://badge.fury.io/py/PyTrustNFe.svg)](https://badge.fury.io/py/PyTrustNFe) @@ -10,28 +9,28 @@ Dependências: * PyXmlSec * lxml * signxml -* suds -* suds_requests +* suds-jurko +* suds-jurko-requests * reportlab * Jinja2 + NFSe - Cidades atendidas --------------- -* [Ariss](cidades/ariss.md) - 4 cidades atendidas +----------------------------- +* **Paulistana** - São Paulo/SP +* **Nota Carioca** - Rio de Janeiro/RJ +* **Imperial** - Petrópolis/RH +* [Susesu](cidades/susesu.md) - 3 cidades atendidas * [Simpliss](cidades/simpliss.md) - 18 cidade atendidas - +* [GINFES](cidaes/ginfes.md) - 79 cidades atendidas +* [DSF](cidades/dsf.md) - 7 cidades atendidas Roadmap -------------- Teste unitários -Emissão de NFCe - -Compatibilidade [python 2 e 3](https://github.com/danimaribeiro/PyTrustNFe/pull/6) - Implementar novos provedores de NFSe * [Betha](cidades/betha.md) - 81 cidades atendidas WIP -* [GINFES](cidades/ginfes.md) - 79 cidades atendidas * [WebISS](cidades/webiss.md) - 51 cidades atendidas * [ISSIntel](cidades/issintel.md) - 32 cidades atendidas * [ISSNET](cidades/issnet.md) - 32 cidades atendidas @@ -39,7 +38,7 @@ Implementar novos provedores de NFSe Exemplos de uso da NFe ---------------- +----------------------------- Consulta Cadastro por CNPJ: @@ -52,7 +51,102 @@ certificado = Certificado(certificado, 'senha_pfx') obj = {'cnpj': '12345678901234', 'estado': '42'} resposta = consulta_cadastro(certificado, obj=obj, ambiente=1, estado='42') ``` +Consulta Distribuição NF-e sem Validação de Esquema: +```python +from pytrustnfe.certificado import Certificado +from pytrustnfe.nfe import consulta_distribuicao_nfe, xml_consulta_distribuicao_nfe + +certificado = open("/path/certificado.pfx", "r").read() +certificado = Certificado(certificado, 'senha_pfx') +# Gerando xml e enviado consulta por Ultimo NSU +response1 = consulta_distribuicao_nfe( + certificado, + ambiente=1, + estado='42', + modelo='55', + cnpj_cpf='12345678901234', + ultimo_nsu='123456789101213' +) + +# Gerando xml e enviado consulta por Chave +response2 = consulta_distribuicao_nfe( + certificado, + ambiente=1, + estado='42', + modelo='55', + cnpj_cpf='12345678901234', + chave_nfe='012345678901234567890123456789012345678912' +) + +# Gerando xml e enviado consulta por NSU +response3 = consulta_distribuicao_nfe( + certificado, + ambiente=1, + estado='42', + modelo='55', + cnpj_cpf='12345678901234', + nsu='123456789101213' +) +``` + +Consulta Distribuição NF-e com Validação de Esquema: +```python +from pytrustnfe.certificado import Certificado +from pytrustnfe.nfe import consulta_distribuicao_nfe, xml_consulta_distribuicao_nfe +from pytrustnfe.xml.validate import valida_nfe, SCHEMA_DFE + +certificado = open("/path/certificado.pfx", "r").read() +certificado = Certificado(certificado, 'senha_pfx') + +# Gerando XML para Consulta por Ultimo NSU +xml1 = xml_consulta_distribuicao_nfe( + certificado, + ambiente=1, + estado='42', + cnpj_cpf='12345678901234', + ultimo_nsu='123456789101213' +) + +# Validando o XML com Esquema +if valida_nfe(xml1, SCHEMA_DFE): + Warning("Erro na validação do esquema") + +# Gerando XML para Consulta por Chave +xml2 = xml_consulta_distribuicao_nfe( + certificado, + ambiente=1, + estado='42', + cnpj_cpf='12345678901234', + chave_nfe='012345678901234567890123456789012345678912' +) + +# Validando o XML com Esquema +if valida_nfe(xml2, SCHEMA_DFE): + Warning("Erro na validação do esquema") + +# Gerando XML para Consulta por NSU +xml3 = xml_consulta_distribuicao_nfe( + certificado, + ambiente=1, + estado='42', + cnpj_cpf='12345678901234', + nsu='123456789101213' +) + +# Validando o XML com Esquema +if valida_nfe(xml3, SCHEMA_DFE): + Warning("Erro na validação do esquema") + +# Enviando xml de consulta para sefaz +response = consulta_distribuicao_nfe( + certificado, + ambiente=1, + estado='42', + modelo='55', + xml=xml1 +) +``` Exemplo de uso da NFSe Paulistana --------------------------------- diff --git a/pytrustnfe/nfe/templates/NfeAutorizacao.xml b/pytrustnfe/nfe/templates/NfeAutorizacao.xml index bf1cc8b..0eb2e3c 100644 --- a/pytrustnfe/nfe/templates/NfeAutorizacao.xml +++ b/pytrustnfe/nfe/templates/NfeAutorizacao.xml @@ -116,6 +116,7 @@ {% endif %} {% endif %} {{ dest.xNome|normalize|escape }} + {% if dest.enderDest is defined %} {{ dest.enderDest.xLgr|normalize|escape }} {{ dest.enderDest.nro }} @@ -129,6 +130,7 @@ {{ dest.enderDest.xPais }} {{ dest.enderDest.fone }} + {% endif %} {{ dest.indIEDest }} {% if dest.IE != '' -%}{{ dest.IE }}{% endif %} {{ dest.ISUF }} @@ -141,6 +143,7 @@ {{ NFe.infNFe.retirada.CNPJ }} {{ NFe.infNFe.retirada.CPF }} + {{ NFe.infNFe.retirada.xNome|normalize|escape }} {{ NFe.infNFe.retirada.xLgr|normalize|escape }} {{ NFe.infNFe.retirada.nro }} {{ NFe.infNFe.retirada.xCpl|normalize|escape }} @@ -148,12 +151,19 @@ {{ NFe.infNFe.retirada.cMun }} {{ NFe.infNFe.retirada.xMun|normalize }} {{ NFe.infNFe.retirada.UF }} + {{ NFe.infNFe.retirada.CEP }} + {{ NFe.infNFe.retirada.cPais }} + {{ NFe.infNFe.retirada.xPais|normalize|escape }} + {{ NFe.infNFe.retirada.fone }} + {{ NFe.infNFe.retirada.email }} + {{ NFe.infNFe.retirada.IE }} {% endif %} {% if NFe.infNFe.entrega is defined %} {{ NFe.infNFe.entrega.CNPJ }} {{ NFe.infNFe.entrega.CPF }} + {{ NFe.infNFe.entrega.xNome|normalize|escape }} {{ NFe.infNFe.entrega.xLgr|normalize|escape }} {{ NFe.infNFe.entrega.nro }} {{ NFe.infNFe.entrega.xCpl|normalize|escape }} @@ -161,6 +171,12 @@ {{ NFe.infNFe.entrega.cMun }} {{ NFe.infNFe.entrega.xMun }} {{ NFe.infNFe.entrega.UF }} + {{ NFe.infNFe.entrega.CEP }} + {{ NFe.infNFe.entrega.cPais }} + {{ NFe.infNFe.entrega.xPais|normalize|escape }} + {{ NFe.infNFe.entrega.fone }} + {{ NFe.infNFe.entrega.email }} + {{ NFe.infNFe.entrega.IE }} {% endif %} {% if NFe.infNFe.autXML %} @@ -243,7 +259,9 @@ {% endfor %} {% endif %} - {{ prod.xPed }} + {% if NFe.infNFe.compra is defined %} + {{ NFe.infNFe.compra.xPed }} + {% endif %} {{ prod.nItemPed }} {{ prod.nFCI }} {% for rastro in prod.rastro %} @@ -258,6 +276,7 @@ {% for med in prod.med %} {{ med.cProdANVISA }} + {{ med.xMotivoIsencao }} {{ med.vPMC }} {% endfor %} @@ -266,6 +285,7 @@ {% with imposto = det.imposto %} {{ imposto.vTotTrib }} + {% if imposto.ICMS is defined %} {% if imposto.ICMS.CST == '00' -%} @@ -365,6 +385,7 @@ {{ imposto.ICMS.CST }} {{ imposto.ICMS.vBCSTRet }} {{ imposto.ICMS.pST }} + {{ imposto.ICMS.vICMSSubstituto }} {{ imposto.ICMS.vICMSSTRet }} {{ imposto.ICMS.vBCFCPSTRet }} {{ imposto.ICMS.pFCPSTRet }} @@ -443,9 +464,18 @@ {{ imposto.ICMSST.orig }} {{ imposto.ICMSST.CST }} {{ imposto.ICMSST.vBCSTRet }} + {{ imposto.ICMSST.pST }} + {{ imposto.ICMSST.vICMSSubstituto }} {{ imposto.ICMSST.vICMSSTRet }} + {{ imposto.ICMSST.vBCFCPSTRet }} + {{ imposto.ICMSST.pFCPSTRet }} + {{ imposto.ICMSST.vFCPSTRet }} {{ imposto.ICMSST.vBCSTDest }} {{ imposto.ICMSST.vICMSSTDest }} + {{ imposto.ICMSST.pRedBCEfet }} + {{ imposto.ICMSST.vBCEfet }} + {{ imposto.ICMSST.pICMSEfet }} + {{ imposto.ICMSST.vICMSEfet }} {% endif %} {% if imposto.ICMS.CST == '101' -%} @@ -500,6 +530,7 @@ {{ imposto.ICMS.CST }} {{ imposto.ICMS.vBCSTRet }} {{ imposto.ICMS.pST }} + {{ imposto.ICMS.vICMSSubstituto }} {{ imposto.ICMS.vICMSSTRet }} {{ imposto.ICMS.vBCFCPSTRet }} {{ imposto.ICMS.pFCPSTRet }} @@ -529,37 +560,58 @@ {% endif %} - {% if NFe.infNFe.ide.mod != '65' %} - - {{ imposto.IPI.clEnq }} - {{ imposto.IPI.CNPJProd }} - {{ imposto.IPI.cSelo }} - {{ imposto.IPI.qSelo }} - {{ imposto.IPI.cEnq }} - {% if imposto.IPI.CST in ('00', '49', '50', '99') %} - - {{ imposto.IPI.CST }} - {{ imposto.IPI.vBC }} - {{ imposto.IPI.pIPI }} - {{ imposto.IPI.qUnid }} - {{ imposto.IPI.vUnid }} - {{ imposto.IPI.vIPI }} - - {% endif %} - {% if imposto.IPI.CST in ('01', '02', '03', '04', '51', '52', '53', '54', '55') %} - - {{ imposto.IPI.CST }} - - {% endif %} - - {% if imposto.II is defined %} - - {{ imposto.II.vBC }} - {{ imposto.II.vDespAdu }} - {{ imposto.II.vII }} - {{ imposto.II.vIOF }} - {% endif %} + {% if NFe.infNFe.ide.mod != '65' and imposto.IPI is defined %} + + {{ imposto.IPI.clEnq }} + {{ imposto.IPI.CNPJProd }} + {{ imposto.IPI.cSelo }} + {{ imposto.IPI.qSelo }} + {{ imposto.IPI.cEnq }} + {% if imposto.IPI.CST in ('00', '49', '50', '99') %} + + {{ imposto.IPI.CST }} + {{ imposto.IPI.vBC }} + {{ imposto.IPI.pIPI }} + {{ imposto.IPI.qUnid }} + {{ imposto.IPI.vUnid }} + {{ imposto.IPI.vIPI }} + + {% endif %} + {% if imposto.IPI.CST in ('01', '02', '03', '04', '51', '52', '53', '54', '55') %} + + {{ imposto.IPI.CST }} + + {% endif %} + + {% if imposto.II is defined %} + + {{ imposto.II.vBC }} + {{ imposto.II.vDespAdu }} + {{ imposto.II.vII }} + {{ imposto.II.vIOF }} + + {% endif %} + {% endif %} + {% if imposto.ISSQN is defined %} + + {{ imposto.ISSQN.vBC }} + {{ imposto.ISSQN.vAliq }} + {{ imposto.ISSQN.vISSQN }} + {{ imposto.ISSQN.cMunFG }} + {{ imposto.ISSQN.cListServ }} + {{ imposto.ISSQN.vDeducao }} + {{ imposto.ISSQN.vOutro }} + {{ imposto.ISSQN.vDescIncond }} + {{ imposto.ISSQN.vDescCond }} + {{ imposto.ISSQN.vDeducao }} + {{ imposto.ISSQN.indISS }} + {{ imposto.ISSQN.cServico }} + {{ imposto.ISSQN.cMun }} + {{ imposto.ISSQN.cPais }} + {{ imposto.ISSQN.nProcesso }} + {{ imposto.ISSQN.indIncentivo }} + {% endif %} {% if imposto.PIS.CST in ('01', '02') %} @@ -637,33 +689,13 @@ {% endif %} {% if imposto.COFINSST is defined %} - + {{ imposto.COFINSST.vBC }} {{ imposto.COFINSST.pCOFINS }} {{ imposto.COFINSST.qBCProd }} {{ imposto.COFINSST.vAliqProd }} {{ imposto.COFINSST.vCOFINS }} - - {% endif %} - {% if imposto.ISSQN is defined %} - - {{ imposto.ISSQN.vBC }} - {{ imposto.ISSQN.vAliq }} - {{ imposto.ISSQN.vISSQN }} - {{ imposto.ISSQN.cMunFG }} - {{ imposto.ISSQN.cListServ }} - {{ imposto.ISSQN.vDeducao }} - {{ imposto.ISSQN.vOutro }} - {{ imposto.ISSQN.vDescIncond }} - {{ imposto.ISSQN.vDescCond }} - {{ imposto.ISSQN.vDeducao }} - {{ imposto.ISSQN.indISS }} - {{ imposto.ISSQN.cServico }} - {{ imposto.ISSQN.cMun }} - {{ imposto.ISSQN.cPais }} - {{ imposto.ISSQN.nProcesso }} - {{ imposto.ISSQN.vDeducao }} - + {% endif %} {% if imposto.ICMSUFDest is defined %} @@ -830,8 +862,8 @@ {{ pag.card.cAut }} {% endif %} - {{ pag.vTroco }} + {{ pag.vTroco }} {% endfor %} {% endif %} @@ -855,6 +887,16 @@ {% endfor %} {% endif %} + {% if NFe.infNFe.infRespTec is defined %} + + {{ NFe.infNFe.infRespTec.CNPJ }} + {{ NFe.infNFe.infRespTec.xContato }} + {{ NFe.infNFe.infRespTec.email }} + {{ NFe.infNFe.infRespTec.fone }} + {{ NFe.infNFe.infRespTec.idCSRT }} + {{ NFe.infNFe.infRespTec.hashCSRT }} + + {% endif %} {% if NFe.infNFe.exporta is defined %} {{ NFe.infNFe.exporta.UFSaidaPais }} @@ -870,6 +912,10 @@ {% endif %} + + {{ NFe.infNFe.qrCode }} + {{ NFe.infNFe.urlChave }} + {% endfor %} diff --git a/requirements.txt b/requirements.txt index 428cdb7..4a3ce46 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -lxml >= 3.5.0, < 4 +lxml nose mock coveralls @@ -10,8 +10,9 @@ suds >= 0.4 suds_requests >= 0.3 defusedxml >= 0.4.1, < 0.6 eight >= 0.3.0, < 0.5 -cryptography >= 1.8, < 1.10 -pyOpenSSL >= 16.0.0, < 17 +cryptography >= 1.8, < 3 +pyOpenSSL < 19, >= 17.5.0 certifi >= 2015.11.20.1 reportlab pytz +zeep \ No newline at end of file diff --git a/setup.py b/setup.py index e6a03a2..1aa8358 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,9 @@ # coding=utf-8 from setuptools import setup, find_packages -VERSION = "1.0.1.post3" + +VERSION = "1.0.6" + setup( name="pytrustnfe", @@ -34,13 +36,14 @@ later (LGPLv2+)', license='LGPL-v2.1+', description='PyTrustNFe é uma biblioteca para envio de NF-e', long_description=open('README.md', 'r').read(), + long_description_content_type='text/markdown', install_requires=[ 'Jinja2 >= 2.8', 'signxml >= 2.4.0', - 'lxml >= 3.5.0, < 4', 'suds >= 0.4', 'suds_requests >= 0.3', 'reportlab', + 'lxml', 'pytz', 'zeep' ],