Browse Source

Implementado emissao NFC-e

pull/1/head
Junior Tada 11 years ago
parent
commit
863825db5e
  1. 11
      pynfe/processamento/assinatura.py
  2. 1
      pynfe/processamento/comunicacao.py
  3. 6
      pynfe/processamento/serializacao.py

11
pynfe/processamento/assinatura.py

@ -30,12 +30,16 @@ class AssinaturaA1(Assinatura):
def assinar(self, xml, retorna_string=False): def assinar(self, xml, retorna_string=False):
try: try:
# No raiz do XML de saida # No raiz do XML de saida
tag = 'infNFe'; # tag que será assinada
raiz = etree.Element('Signature', xmlns='http://www.w3.org/2000/09/xmldsig#') raiz = etree.Element('Signature', xmlns='http://www.w3.org/2000/09/xmldsig#')
siginfo = etree.SubElement(raiz, 'SignedInfo') siginfo = etree.SubElement(raiz, 'SignedInfo')
etree.SubElement(siginfo, 'CanonicalizationMethod', Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315') 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') 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') 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/2000/09/xmldsig#enveloped-signature')
etree.SubElement(trans, 'Transform', Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315') etree.SubElement(trans, 'Transform', Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315')
@ -50,8 +54,7 @@ class AssinaturaA1(Assinatura):
with open('testes.xml', 'w') as arquivo: with open('testes.xml', 'w') as arquivo:
arquivo.write(etree.tostring(xml, encoding="unicode", pretty_print=False)) 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() xml = etree.parse('funfa.xml').getroot()
if retorna_string: if retorna_string:

1
pynfe/processamento/comunicacao.py

@ -253,6 +253,7 @@ class ComunicacaoSefaz(Comunicacao):
xml = etree.tostring(xml, encoding='unicode', pretty_print=False).replace('\n','') xml = etree.tostring(xml, encoding='unicode', pretty_print=False).replace('\n','')
xml = xml_declaration + xml xml = xml_declaration + xml
# Faz o request com o servidor # Faz o request com o servidor
print (xml)
result = requests.post(url, xml, headers=self._post_header(), cert=chave_cert, verify=False) result = requests.post(url, xml, headers=self._post_header(), cert=chave_cert, verify=False)
if result == 200: if result == 200:
result.encoding='utf-8' result.encoding='utf-8'

6
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, '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, '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 # Apenas NF-e
if nota_fiscal.modelo == 55: if nota_fiscal.modelo == 55:
@ -470,6 +470,10 @@ class SerializacaoXML(Serializacao):
# Somente NFC-e # Somente NFC-e
if nota_fiscal.modelo == 65: if nota_fiscal.modelo == 65:
# Transporte
transp = etree.SubElement(raiz, 'transp')
etree.SubElement(transp, 'modFrete').text = str(9)
# Pagamento
pag = etree.SubElement(raiz, 'pag') 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, '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) etree.SubElement(pag, 'vPag').text = str(nota_fiscal.totais_icms_total_nota)

Loading…
Cancel
Save