|
|
|
@ -27,10 +27,9 @@ class ComunicacaoSefaz(Comunicacao): |
|
|
|
_versao = VERSAO_PADRAO |
|
|
|
_assinatura = AssinaturaA1 |
|
|
|
|
|
|
|
def autorizacao(self, nota_fiscal): |
|
|
|
# tipo de nota, nfce ou nfe para pegar url correta |
|
|
|
tipo = 'nfce' if nota_fiscal.modelo == 65 else 'nfe' |
|
|
|
url = self._get_url(tipo=tipo, consulta='AUTORIZACAO') |
|
|
|
def autorizacao(self, modelo, nota_fiscal): |
|
|
|
# url do serviço |
|
|
|
url = self._get_url(modelo=modelo, consulta='AUTORIZACAO') |
|
|
|
|
|
|
|
# Monta XML do corpo da requisição |
|
|
|
raiz = etree.Element('enviNFe') |
|
|
|
@ -38,7 +37,12 @@ class ComunicacaoSefaz(Comunicacao): |
|
|
|
etree.SubElement(raiz, 'idLote').text = str(1) # numero autoincremental gerado pelo sistema |
|
|
|
etree.SubElement(raiz, 'indSinc').text = str(1) # 0 para assincrono, 1 para sincrono |
|
|
|
etree.SubElement(raiz, 'NFe').text = nota_fiscal # conjunto de nfe tramistidas (max 50) |
|
|
|
|
|
|
|
dados = etree.tostring(raiz, encoding="UTF-8") |
|
|
|
# Monta XML para envio da requisição |
|
|
|
xml = self._construir_xml_status_pr(cabecalho=self._cabecalho_soap(), dados=dados, url=url) |
|
|
|
return str(xml, 'utf-8').replace('<', '<').replace('>', '>').replace('\'', '"').replace('\n', '') |
|
|
|
#return self._post(url, xml, self._post_header()) |
|
|
|
|
|
|
|
def cancelar(self, nota_fiscal): |
|
|
|
pass |
|
|
|
|
|
|
|
@ -57,7 +61,7 @@ class ComunicacaoSefaz(Comunicacao): |
|
|
|
etree.SubElement(raiz, 'tpAmb').text = str(self._ambiente) |
|
|
|
etree.SubElement(raiz, 'cUF').text = CODIGOS_ESTADOS[self.uf.upper()] |
|
|
|
etree.SubElement(raiz, 'xServ').text = 'STATUS' |
|
|
|
dados = etree.tostring(raiz, encoding='UTF-8') |
|
|
|
dados = etree.tostring(raiz, encoding="UTF-8") |
|
|
|
# Monta XML para envio da requisição |
|
|
|
if self.uf.upper() == 'PR': |
|
|
|
xml = self._construir_xml_status_pr(cabecalho=self._cabecalho_soap(), dados=dados, url=url) |
|
|
|
@ -125,15 +129,15 @@ class ComunicacaoSefaz(Comunicacao): |
|
|
|
|
|
|
|
return retorno |
|
|
|
|
|
|
|
def _get_url(self, tipo, consulta): |
|
|
|
def _get_url(self, modelo, consulta): |
|
|
|
if self._ambiente == 1: |
|
|
|
ambiente = 'https://' |
|
|
|
else: |
|
|
|
ambiente = 'https://homologacao.' |
|
|
|
if tipo == 'nfe': |
|
|
|
if modelo == 'nfe': |
|
|
|
# nfe Ex: https://nfe.fazenda.pr.gov.br/nfe/NFeStatusServico3 |
|
|
|
url = ambiente + NFE[self.uf.upper()][consulta] |
|
|
|
elif tipo == 'nfce': |
|
|
|
elif modelo == 'nfce': |
|
|
|
# nfce Ex: https://homologacao.nfce.fazenda.pr.gov.br/nfce/NFeStatusServico3 |
|
|
|
url = ambiente + NFCE[self.uf.upper()][consulta] |
|
|
|
else: |
|
|
|
@ -148,7 +152,7 @@ class ComunicacaoSefaz(Comunicacao): |
|
|
|
etree.SubElement(raiz, 'cUF').text = str(41) |
|
|
|
etree.SubElement(raiz, 'versaoDados').text = VERSAO_PADRAO |
|
|
|
|
|
|
|
return etree.tostring(raiz, encoding='UTF-8') |
|
|
|
return etree.tostring(raiz, encoding="UTF-8") |
|
|
|
|
|
|
|
def _construir_xml_soap(self, cabecalho, metodo, tag_metodo, dados): |
|
|
|
"""Mota o XML para o envio via SOAP""" |
|
|
|
@ -163,7 +167,7 @@ class ComunicacaoSefaz(Comunicacao): |
|
|
|
etree.SubElement(met, 'nfeCabecMsg').text = cabecalho |
|
|
|
etree.SubElement(met, 'nfeDadosMsg').text = dados |
|
|
|
|
|
|
|
return etree.tostring(raiz, encoding='utf-8', xml_declaration=True) |
|
|
|
return etree.tostring(raiz, encoding="UTF-8", xml_declaration=True) |
|
|
|
|
|
|
|
def _construir_xml_status_pr(self, cabecalho, dados, url): |
|
|
|
u"""Mota o XML para o envio via SOAP""" |
|
|
|
@ -171,9 +175,9 @@ class ComunicacaoSefaz(Comunicacao): |
|
|
|
raiz = etree.Element('{%s}Envelope'%NAMESPACE_SOAP, nsmap={'soap': NAMESPACE_SOAP}, xmlns=url) |
|
|
|
etree.SubElement(raiz, '{%s}Header'%NAMESPACE_SOAP).text = cabecalho |
|
|
|
body = etree.SubElement(raiz, '{%s}Body'%NAMESPACE_SOAP) |
|
|
|
etree.SubElement(body, 'nfeDadosMsg').text = dados |
|
|
|
etree.SubElement(body, 'nfeDadosMsg').text = str(dados) |
|
|
|
|
|
|
|
return etree.tostring(raiz, encoding='UTF-8', xml_declaration=True) |
|
|
|
return etree.tostring(raiz, encoding="UTF-8", xml_declaration=True) |
|
|
|
|
|
|
|
def _post_header(self): |
|
|
|
u"""Retorna um dicionário com os atributos para o cabeçalho da requisição HTTP""" |
|
|
|
|