Skip to content

Commit

Permalink
[FIX] Removing useless code for NFCe, adjusting xml template for NFCe
Browse files Browse the repository at this point in the history
  • Loading branch information
danimaribeiro committed Oct 3, 2018
1 parent 4f3da1a commit a252d86
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 469 deletions.
59 changes: 4 additions & 55 deletions pytrustnfe/nfe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@


import os
import hashlib
import binascii
from lxml import etree
from .assinatura import Assinatura
from pytrustnfe.xml import render_xml, sanitize_response
from pytrustnfe.utils import gerar_chave, ChaveNFe
from pytrustnfe.Servidores import localizar_url, localizar_qrcode
from pytrustnfe.Servidores import localizar_url
from pytrustnfe.certificado import extract_cert_and_key_from_pfx, save_cert_key

# Zeep
Expand Down Expand Up @@ -38,54 +36,6 @@ def _generate_nfe_id(**kwargs):
item['infNFe']['ide']['cDV'] = chave_nfe[len(chave_nfe) - 1:]


def _add_qrCode(xml, **kwargs):
xml = etree.fromstring(xml)
inf_nfe = kwargs['NFes'][0]['infNFe']
nfe = xml.find(".//{http://www.portalfiscal.inf.br/nfe}NFe")
infnfesupl = etree.Element('infNFeSupl')
qrcode = etree.Element('qrCode')
chave_nfe = inf_nfe['Id'][3:]
dh_emissao = binascii.hexlify(inf_nfe['ide']['dhEmi'].encode()).decode()
versao = '100'
ambiente = kwargs['ambiente']
valor_total = inf_nfe['total']['vNF']
dest_cpf = 'Inexistente'
dest = nfe.find(".//{http://www.portalfiscal.inf.br/nfe}dest")

if inf_nfe.get('dest', False):
if inf_nfe['dest'].get('CPF', False):
dest_cpf = inf_nfe['dest']['CPF']
dest = etree.Element('dest')
cpf = etree.Element('CPF')
cpf.text = dest_cpf
dest.append(cpf)

icms_total = inf_nfe['total']['vICMS']
dig_val = binascii.hexlify(xml.find(
".//{http://www.w3.org/2000/09/xmldsig#}DigestValue").text.encode()).decode()
cid_token = kwargs['NFes'][0]['infNFe']['codigo_seguranca']['cid_token']
csc = kwargs['NFes'][0]['infNFe']['codigo_seguranca']['csc']

c_hash_QR_code = "chNFe={0}&nVersao={1}&tpAmb={2}&cDest={3}&dhEmi={4}&vNF\
={5}&vICMS={6}&digVal={7}&cIdToken={8}{9}".\
format(chave_nfe, versao, ambiente, dest_cpf, dh_emissao,
valor_total, icms_total, dig_val, cid_token, csc)
c_hash_QR_code = hashlib.sha1(c_hash_QR_code.encode()).hexdigest()

QR_code_url = "?chNFe={0}&nVersao={1}&tpAmb={2}&{3}dhEmi={4}&vNF={5}&vICMS\
={6}&digVal={7}&cIdToken={8}&cHashQRCode={9}".\
format(chave_nfe, versao, ambiente,
'cDest={}&'.format(dest_cpf) if dest_cpf != 'Inexistente'
else '', dh_emissao, valor_total, icms_total, dig_val,
cid_token, c_hash_QR_code)
qr_code_server = localizar_qrcode(kwargs['estado'], ambiente)
qrcode_text = qr_code_server + QR_code_url
qrcode.text = etree.CDATA(qrcode_text)
infnfesupl.append(qrcode)
nfe.insert(1, infnfesupl)
return etree.tostring(xml, encoding=str)


def _render(certificado, method, sign, **kwargs):
path = os.path.join(os.path.dirname(__file__), 'templates')
xmlElem_send = render_xml(path, '%s.xml' % method, True, **kwargs)
Expand All @@ -107,9 +57,6 @@ def _render(certificado, method, sign, **kwargs):
xml_send = signer.assina_xml(
xmlElem_send, kwargs['manifesto']['identificador'])

if modelo == '65':
xml_send = _add_qrCode(xml_send, **kwargs)

else:
xml_send = etree.tostring(xmlElem_send, encoding=str)
return xml_send
Expand All @@ -129,7 +76,9 @@ def _send(certificado, method, **kwargs):
session.verify = False
transport = Transport(session=session)

xml = etree.fromstring(xml_send)
parser = etree.XMLParser(strip_cdata=False)
xml = etree.fromstring(xml_send, parser=parser)

client = Client(base_url, transport=transport)

port = next(iter(client.wsdl.port_types))
Expand Down
4 changes: 4 additions & 0 deletions pytrustnfe/nfe/templates/NfeAutorizacao.xml
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,10 @@
</compra>
{% endif %}
</infNFe>
<infNFeSupl>
<qrCode>{{ NFe.infNFe.qrCode }}</qrCode>
<urlChave>{{ NFe.infNFe.urlChave }}</urlChave>
</infNFeSupl>
</NFe>
{% endfor %}
</enviNFe>
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup, find_packages


VERSION = "1.0.11"
VERSION = "1.0.12"


setup(
Expand Down
34 changes: 0 additions & 34 deletions tests/test_add_qr_code.py

This file was deleted.

189 changes: 0 additions & 189 deletions tests/xml_com_qrcode.xml

This file was deleted.

Loading

0 comments on commit a252d86

Please sign in to comment.