From 863825db5e4b58477f0ce17200a69763864c61aa Mon Sep 17 00:00:00 2001 From: Junior Tada Date: Mon, 3 Aug 2015 12:38:05 -0300 Subject: [PATCH] Implementado emissao NFC-e --- pynfe/processamento/assinatura.py | 13 ++++++++----- pynfe/processamento/comunicacao.py | 1 + pynfe/processamento/serializacao.py | 6 +++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pynfe/processamento/assinatura.py b/pynfe/processamento/assinatura.py index fde27b6..a975c0d 100644 --- a/pynfe/processamento/assinatura.py +++ b/pynfe/processamento/assinatura.py @@ -30,12 +30,16 @@ class AssinaturaA1(Assinatura): def assinar(self, xml, retorna_string=False): try: # No raiz do XML de saida + tag = 'infNFe'; # tag que será assinada raiz = etree.Element('Signature', xmlns='http://www.w3.org/2000/09/xmldsig#') siginfo = etree.SubElement(raiz, 'SignedInfo') etree.SubElement(siginfo, 'CanonicalizationMethod', Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315') etree.SubElement(siginfo, 'SignatureMethod', Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1') - #ref = etree.SubElement(siginfo, 'Reference', URI='#'+xml.findall('infNFe')[0].attrib['Id']) - ref = etree.SubElement(siginfo, 'Reference', URI='#'+xml.findall('infEvento')[0].attrib['Id']) + if xml.findall('infNFe')[0].attrib['Id']: + ref = etree.SubElement(siginfo, 'Reference', URI='#'+xml.findall('infNFe')[0].attrib['Id']) + elif xml.findall('infEvento')[0].attrib['Id']: + tag = 'infEvento' + ref = etree.SubElement(siginfo, 'Reference', URI='#'+xml.findall('infEvento')[0].attrib['Id']) trans = etree.SubElement(ref, 'Transforms') etree.SubElement(trans, 'Transform', Algorithm='http://www.w3.org/2000/09/xmldsig#enveloped-signature') etree.SubElement(trans, 'Transform', Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315') @@ -49,9 +53,8 @@ class AssinaturaA1(Assinatura): with open('testes.xml', 'w') as arquivo: arquivo.write(etree.tostring(xml, encoding="unicode", pretty_print=False)) - - #subprocess.call(['xmlsec1', '--sign', '--pkcs12', self.certificado, '--pwd', self.senha, '--crypto', 'openssl', '--output', 'funfa.xml', '--id-attr:Id', 'infNFe', 'testes.xml']) - subprocess.call(['xmlsec1', '--sign', '--pkcs12', self.certificado, '--pwd', self.senha, '--crypto', 'openssl', '--output', 'funfa.xml', '--id-attr:Id', 'infEvento', 'testes.xml']) + + subprocess.call(['xmlsec1', '--sign', '--pkcs12', self.certificado, '--pwd', self.senha, '--crypto', 'openssl', '--output', 'funfa.xml', '--id-attr:Id', tag, 'testes.xml']) xml = etree.parse('funfa.xml').getroot() if retorna_string: diff --git a/pynfe/processamento/comunicacao.py b/pynfe/processamento/comunicacao.py index 5f22ff1..e43e5f3 100644 --- a/pynfe/processamento/comunicacao.py +++ b/pynfe/processamento/comunicacao.py @@ -253,6 +253,7 @@ class ComunicacaoSefaz(Comunicacao): xml = etree.tostring(xml, encoding='unicode', pretty_print=False).replace('\n','') xml = xml_declaration + xml # Faz o request com o servidor + print (xml) result = requests.post(url, xml, headers=self._post_header(), cert=chave_cert, verify=False) if result == 200: result.encoding='utf-8' diff --git a/pynfe/processamento/serializacao.py b/pynfe/processamento/serializacao.py index 8225a28..7f6f9f4 100644 --- a/pynfe/processamento/serializacao.py +++ b/pynfe/processamento/serializacao.py @@ -426,7 +426,7 @@ class SerializacaoXML(Serializacao): etree.SubElement(icms_total, 'vOutro').text = str('{:.2f}').format(nota_fiscal.totais_icms_outras_despesas_acessorias) etree.SubElement(icms_total, 'vNF').text = str('{:.2f}').format(nota_fiscal.totais_icms_total_nota) - etree.SubElement(icms_total, 'vTotTrib').text = str('{:.2f}').format(nota_fiscal.totais_tributos_aproximado) + #etree.SubElement(icms_total, 'vTotTrib').text = str('{:.2f}').format(nota_fiscal.totais_tributos_aproximado) # Apenas NF-e if nota_fiscal.modelo == 55: @@ -470,6 +470,10 @@ class SerializacaoXML(Serializacao): # Somente NFC-e if nota_fiscal.modelo == 65: + # Transporte + transp = etree.SubElement(raiz, 'transp') + etree.SubElement(transp, 'modFrete').text = str(9) + # Pagamento pag = etree.SubElement(raiz, 'pag') etree.SubElement(pag, 'tPag').text = '01'# 01=Dinheiro 02=Cheque 03=Cartão de Crédito 04=Cartão de Débito 05=Crédito Loja 10=Vale Alimentação 11=Vale Refeição 12=Vale Presente 13=Vale Combustível 99=Outros etree.SubElement(pag, 'vPag').text = str(nota_fiscal.totais_icms_total_nota)