Example #1
0
def _send(certificado, method, **kwargs):
    # A little hack to test
    path = os.path.join(os.path.dirname(__file__), "templates")
    if (
        method == "TesteEnvioLoteRPS"
        or method == "EnvioLoteRPS"
        or method == "CancelamentoNFe"
    ):
        sign_tag(certificado, **kwargs)

    if method == "TesteEnvioLoteRPS":
        xml_send = render_xml(path, "EnvioLoteRPS.xml", False, **kwargs)
    else:
        xml_send = render_xml(path, "%s.xml" % method, False, **kwargs)
    base_url = "https://nfe.prefeitura.sp.gov.br/ws/lotenfe.asmx?wsdl"

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx, certificado.password)
    cert, key = save_cert_key(cert, key)
    client = get_authenticated_client(base_url, cert, key)

    signer = Assinatura(cert, key, certificado.password)
    xml_send = signer.assina_xml(xml_send, "")

    try:
        response = getattr(client.service, method)(1, xml_send)
    except suds.WebFault as e:
        return {
            "sent_xml": xml_send,
            "received_xml": e.fault.faultstring,
            "object": None,
        }

    response, obj = sanitize_response(response)
    return {"sent_xml": xml_send, "received_xml": response, "object": obj}
Example #2
0
def _send(certificado, method, **kwargs):
    # A little hack to test
    path = os.path.join(os.path.dirname(__file__), 'templates')
    if method == 'TesteEnvioLoteRPS' or method == 'EnvioLoteRPS' \
       or method == 'CancelamentoNFe':
        sign_tag(certificado, **kwargs)

    if method == 'TesteEnvioLoteRPS':
        xml_send = render_xml(path, 'EnvioLoteRPS.xml', False, **kwargs)
    else:
        xml_send = render_xml(path, '%s.xml' % method, False, **kwargs)
    base_url = 'https://nfe.prefeitura.sp.gov.br/ws/lotenfe.asmx?wsdl'

    cert, key = extract_cert_and_key_from_pfx(
        certificado.pfx, certificado.password)
    cert, key = save_cert_key(cert, key)
    client = get_authenticated_client(base_url, cert, key)

    pfx_path = certificado.save_pfx()
    signer = Assinatura(pfx_path, certificado.password)
    xml_send = signer.assina_xml(xml_send, '')

    try:
        response = getattr(client.service, method)(1, xml_send)
    except suds.WebFault, e:
        return {
            'sent_xml': xml_send,
            'received_xml': e.fault.faultstring,
            'object': None
        }
Example #3
0
def _send(certificado, method, **kwargs):
    # A little hack to test
    path = os.path.join(os.path.dirname(__file__), 'templates')
    if method == 'TesteEnvioLoteRPS' or method == 'EnvioLoteRPS' \
       or method == 'CancelamentoNFe':
        sign_tag(certificado, **kwargs)

    if method == 'TesteEnvioLoteRPS':
        xml_send = render_xml(path, 'EnvioLoteRPS.xml', False, **kwargs)
    else:
        xml_send = render_xml(path, '%s.xml' % method, False, **kwargs)
    base_url = 'https://nfe.prefeitura.sp.gov.br/ws/lotenfe.asmx?wsdl'

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx,
                                              certificado.password)
    cert, key = save_cert_key(cert, key)
    client = get_authenticated_client(base_url, cert, key)

    signer = Assinatura(cert, key, certificado.password)
    xml_send = signer.assina_xml(xml_send, '')

    try:
        response = getattr(client.service, method)(1, xml_send)
    except suds.WebFault as e:
        return {
            'sent_xml': xml_send,
            'received_xml': e.fault.faultstring,
            'object': None
        }

    response, obj = sanitize_response(response)
    return {'sent_xml': xml_send, 'received_xml': response, 'object': obj}
def get_objects(nfse):
    xml_rps = render_xml(template_path, 'EnvioRPS.xml', False, nfse=nfse)
    _, obj_rps = sanitize_response(xml_rps)

    xml_lote_rps = render_xml(template_path, 'EnvioLoteRPS.xml', False, nfse=nfse)
    _, obj_lote_rps = sanitize_response(xml_lote_rps)

    return obj_rps, obj_lote_rps
Example #5
0
def _render(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), 'templates')
    if method == 'TesteEnvioLoteRPS' or method == 'EnvioLoteRPS' or method == 'CancelamentoNFe':
        sign_tag(certificado, **kwargs)

    if method == 'TesteEnvioLoteRPS':
        return render_xml(path, 'EnvioLoteRPS.xml', False, **kwargs)
    else:
        return render_xml(path, '%s.xml' % method, False, **kwargs)
Example #6
0
def _render(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), 'templates')
    if method == "testeEnviar":
        xml_send = render_xml(path, 'enviar.xml', True, **kwargs)
    else:
        xml_send = render_xml(path, '%s.xml' % method, False, **kwargs)

    if type(xml_send) != str:
        xml_send = etree.tostring(xml_send)
    return xml_send.decode()
Example #7
0
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)

    modelo = xmlElem_send.find(".//{http://www.portalfiscal.inf.br/nfe}mod")
    modelo = modelo.text if modelo is not None else '55'

    if sign:
        signer = Assinatura(certificado.pfx, certificado.password)
        if method == 'NfeInutilizacao':
            xml_send = signer.assina_xml(xmlElem_send, kwargs['obj']['id'])
        if method == 'NfeAutorizacao':
            xml_send = signer.assina_xml(
                xmlElem_send, kwargs['NFes'][0]['infNFe']['Id'])
        elif method == 'RecepcaoEvento':
            xml_send = signer.assina_xml(
                xmlElem_send, kwargs['eventos'][0]['Id'])
        elif method == 'RecepcaoEventoManifesto':
            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)
    return xml_send
Example #8
0
def _send(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), 'templates')
    if method in ('GerarNfse', 'RecepcionarLoteRps',
                  'RecepcionarLoteRpsSincrono', 'CancelarNfse',
                  'SubstituirNfse'):
        sign_tag(certificado, **kwargs)

    if kwargs['ambiente'] == 'producao':
        url = \
            'http://e-gov.betha.com.br/e-nota-contribuinte-test-ws/nfseWS?wsdl'
    else:
        url = 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/nfseWS?wsdl'

    xml_send = render_xml(path, '%s.xml' % method, False, **kwargs)

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx,
                                              certificado.password)
    cert, key = save_cert_key(cert, key)
    client = get_authenticated_client(url, cert, key)

    pfx_path = certificado.save_pfx()
    signer = Assinatura(pfx_path, certificado.password)
    xml_send = signer.assina_xml(xml_send, '')

    try:
        response = getattr(client.service, method)(1, xml_send)
    except suds.WebFault as e:
        return {
            'sent_xml': xml_send,
            'received_xml': e.fault.faultstring,
            'object': None
        }

    response, obj = sanitize_response(response)
    return {'sent_xml': xml_send, 'received_xml': response, 'object': obj}
Example #9
0
def _send(certificado, method, sign, **kwargs):
    path = os.path.join(os.path.dirname(__file__), 'templates')
    xmlElem_send = render_xml(path, '%s.xml' % method, True, **kwargs)
    modelo = xmlElem_send.find(".//{http://www.portalfiscal.inf.br/nfe}mod")
    modelo = modelo.text if modelo is not None else '55'
    if sign:
        # Caso for autorização temos que adicionar algumas tags tipo
        # cEan, cEANTrib porque o governo sempre complica e não segue padrão
        if method == 'NfeAutorizacao':
            xmlElem_send = _add_required_node(xmlElem_send)

        signer = Assinatura(certificado.pfx, certificado.password)
        if method == 'NfeAutorizacao':
            xml_send = signer.assina_xml(xmlElem_send,
                                         kwargs['NFes'][0]['infNFe']['Id'])
        elif method == 'RecepcaoEventoCancelamento':
            xml_send = signer.assina_xml(xmlElem_send,
                                         kwargs['eventos'][0]['Id'])

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

    else:
        xml_send = etree.tostring(xmlElem_send)

    url = localizar_url(method, kwargs['estado'], modelo, kwargs['ambiente'])
    cabecalho = _build_header(method, **kwargs)

    response, obj = executar_consulta(certificado, url, cabecalho, xml_send)
    return {'sent_xml': xml_send, 'received_xml': response, 'object': obj}
Example #10
0
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)

    modelo = xmlElem_send.find(".//{http://www.portalfiscal.inf.br/nfe}mod")
    modelo = modelo.text if modelo is not None else "55"

    if sign:
        signer = Assinatura(certificado.pfx, certificado.password)
        if method == "NfeInutilizacao":
            xml_send = signer.assina_xml(xmlElem_send, kwargs["obj"]["id"])
        if method == "NfeAutorizacao":
            xml_send = signer.assina_xml(
                xmlElem_send, kwargs["NFes"][0]["infNFe"]["Id"]
            )
        elif method == "RecepcaoEvento":
            xml_send = signer.assina_xml(xmlElem_send, kwargs["eventos"][0]["Id"])
        elif method == "RecepcaoEventoManifesto":
            xml_send = signer.assina_xml(
                xmlElem_send, kwargs["manifesto"]["identificador"]
            )

    else:
        xml_send = etree.tostring(xmlElem_send, encoding=str)
    return xml_send
    def test_serializacao_default(self):
        path = os.path.join(os.path.dirname(__file__), 'XMLs')
        xml = render_xml(path, 'jinja_template.xml', False, tag1='oi',
                         tag2='ola', tag3='comovai')

        result = open(os.path.join(path, 'jinja_result.xml'), 'r').read()
        self.assertEqual(xml + '\n', result)
 def test_serializacao_remove_empty(self):
     path = os.path.join(os.path.dirname(__file__), 'XMLs')
     xmlElem = render_xml(path, 'jinja_template.xml', True, tag1='oi',
                          tag2='ola', tag3='comovai')
     xml = etree.tostring(xmlElem)
     result = open(os.path.join(path, 'jinja_remove_empty.xml'), 'r').read()
     self.assertEqual(xml + '\n', result)
Example #13
0
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)

    modelo = xmlElem_send.find(".//{http://www.portalfiscal.inf.br/nfe}mod")
    modelo = modelo.text if modelo is not None else '55'

    if sign:
        signer = Assinatura(certificado.pfx, certificado.password)
        if method == 'NfeInutilizacao':
            xml_send = signer.assina_xml(xmlElem_send, kwargs['obj']['id'])
        if method == 'NfeAutorizacao':
            xml_send = signer.assina_xml(xmlElem_send,
                                         kwargs['NFes'][0]['infNFe']['Id'])
        elif method == 'RecepcaoEvento':
            xml_send = signer.assina_xml(xmlElem_send,
                                         kwargs['eventos'][0]['Id'])
        elif method == 'RecepcaoEventoManifesto':
            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)
    return xml_send
Example #14
0
def _render(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), "templates")
    xml_send = render_xml(path, f"{method}.xml", False, **kwargs)
    signer = Assinatura(certificado.pfx, certificado.password)
    xml_send = etree.fromstring(xml_send)
    xml_send = signer.assina_xml(xml_send)
    return xml_send
Example #15
0
def _render(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), 'templates')
    xml_send = render_xml(path, '%s.xml' % method, True, **kwargs)

    reference = ''
    signer = Assinatura(certificado.pfx, certificado.password)
    xml_send = signer.assina_xml(xml_send, reference)
    return xml_send
Example #16
0
def _render(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), "templates")
    xml_send = render_xml(path, "%s.xml" % method, False, **kwargs)

    cert, key = extract_cert_and_key_from_pfx(certificado.pfx, certificado.password)
    cert, key = save_cert_key(cert, key)
    signer = Assinatura(cert, key, certificado.password)
    xml_send = signer.assina_xml(xml_send, "")
    return xml_send
Example #17
0
    def test_envio_nfse(self):
        nfse = _get_nfse()

        xml_send = render_xml(self.template_path, 'EnvioLoteRPS.xml', False, nfse=nfse)
        expected_xml = open(os.path.join(self.xml_path, 'xml_send_rps_batch_to_paulistana.xml'), 'r').read()

        _, obj = sanitize_response(xml_send)

        self.assertEqual(obj.Cabecalho.QtdRPS, self.BATCH_SIZE)
        self.assertEqual(xml_send, expected_xml)
Example #18
0
    def test_lote_rps_sem_valores(self):
        xml_lote_rps = render_xml(self.template_path,
                                  'EnvioLoteRPS.xml',
                                  False,
                                  nfse=self.nfse)

        _, obj = sanitize_response(xml_lote_rps)

        for attr in attrs:
            self.assertEqual(getattr(obj.RPS, attr), default_values[attr])
Example #19
0
def _render(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), 'templates')
    xml_send = render_xml(path, '%s.xml' % method, True, **kwargs)

    reference = ''
    if method == 'RecepcionarLoteRpsV3':
        reference = 'rps%s' % kwargs['nfse']['lista_rps'][0]['numero']

    signer = Assinatura(certificado.pfx, certificado.password)
    xml_send = signer.assina_xml(xml_send, reference)
    return xml_send
Example #20
0
def _send(certificado, method, sign, **kwargs):
    path = os.path.join(os.path.dirname(__file__), 'templates')
    xmlElem_send = render_xml(path, '%s.xml' % method, True, **kwargs)
    modelo = xmlElem_send.find(".//{http://www.portalfiscal.inf.br/nfe}mod")
    modelo = modelo.text if modelo is not None else '55'
    if modelo == '65':
        pagamento = etree.Element('pag')
        tipo_pagamento = etree.Element('tPag')
        valor = etree.Element('vPag')
        valor_pago = kwargs['NFes'][0]['infNFe']['total']['vNF']
        metodo_pagamento = kwargs['NFes'][0]['infNFe']['pagamento']
        tipo_pagamento.text, valor.text = metodo_pagamento, valor_pago
        pagamento.append(tipo_pagamento)
        pagamento.append(valor)
        transp = xmlElem_send.find(
            ".//{http://www.portalfiscal.inf.br/nfe}transp")
        transp.addnext(pagamento)

    if sign:
        # Caso for autorização temos que adicionar algumas tags tipo
        # cEan, cEANTrib porque o governo sempre complica e não segue padrão
        if method == 'NfeAutorizacao':
            xmlElem_send = _add_required_node(xmlElem_send)

        signer = Assinatura(certificado.pfx, certificado.password)
        if method == 'NfeInutilizacao':
            xml_send = signer.assina_xml(xmlElem_send, kwargs['obj']['id'])
        if method == 'NfeAutorizacao':
            xml_send = signer.assina_xml(xmlElem_send,
                                         kwargs['NFes'][0]['infNFe']['Id'])
            if 'validate' in kwargs:
                erros = valida_nfe(xml_send)
                if erros:
                    raise NFeValidationException('Erro ao validar NFe',
                                                 erros=erros,
                                                 sent_xml=xml_send)
        elif method == 'RecepcaoEventoCancelamento':
            xml_send = signer.assina_xml(xmlElem_send,
                                         kwargs['eventos'][0]['Id'])

        if method == 'RecepcaoEventoCarta':
            xml_send = signer.assina_xml(xmlElem_send, kwargs['Id'])

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

    else:
        xml_send = etree.tostring(xmlElem_send)

    url = localizar_url(method, kwargs['estado'], modelo, kwargs['ambiente'])
    cabecalho = _build_header(method, **kwargs)

    response, obj = executar_consulta(certificado, url, cabecalho, xml_send)
    return {'sent_xml': xml_send, 'received_xml': response, 'object': obj}
Example #21
0
    def test_serializacao_default(self):
        path = os.path.join(os.path.dirname(__file__), 'XMLs')
        xml = render_xml(path,
                         'jinja_template.xml',
                         False,
                         tag1='oi',
                         tag2='ola',
                         tag3='comovai')

        result = open(os.path.join(path, 'jinja_result.xml'), 'r').read()
        self.assertEqual(xml + "\n", result)
Example #22
0
 def test_serializacao_remove_empty(self):
     path = os.path.join(os.path.dirname(__file__), 'XMLs')
     xmlElem = render_xml(path,
                          'jinja_template.xml',
                          True,
                          tag1='oi',
                          tag2='ola',
                          tag3='comovai')
     xml = etree.tostring(xmlElem, encoding=str)
     result = open(os.path.join(path, 'jinja_remove_empty.xml'), 'r').read()
     self.assertEqual(xml + '\n', result)
 def test_serializacao_remove_empty(self):
     path = os.path.join(os.path.dirname(__file__), "XMLs")
     xmlElem = render_xml(path,
                          "jinja_template.xml",
                          True,
                          tag1="oi",
                          tag2="ola",
                          tag3="comovai")
     xml = etree.tostring(xmlElem, encoding=str)
     result = open(os.path.join(path, "jinja_remove_empty.xml"), "r").read()
     self.assertEqual(xml + "\n", result)
Example #24
0
def _render(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), 'templates')
    xml_send = render_xml(path, '%s.xml' % method, True, **kwargs)

    reference = ''
    if method == 'RecepcionarLoteRpsV3':
        reference = 'rps%s' % kwargs['nfse']['lista_rps'][0]['numero']

    signer = Assinatura(certificado.pfx, certificado.password)
    xml_send = signer.assina_xml(xml_send, reference)
    return xml_send
    def test_serializacao_default(self):
        path = os.path.join(os.path.dirname(__file__), "XMLs")
        xml = render_xml(path,
                         "jinja_template.xml",
                         False,
                         tag1="oi",
                         tag2="ola",
                         tag3="comovai")

        result = open(os.path.join(path, "jinja_result.xml"), "r").read()
        self.assertEqual(xml + "\n", result)
Example #26
0
def _render(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), 'templates')
    xml_send = render_xml(path, '%s.xml' % method, True, **kwargs)

    reference = ''
    if method == 'GerarNfse':
        reference = 'r%s' % kwargs['rps']['numero']
    elif method == 'CancelarNfse':
        reference = 'Cancelamento_NF%s' % kwargs['cancelamento']['numero_nfse']

    signer = Assinatura(certificado.pfx, certificado.password)
    xml_send = signer.assina_xml(xml_send, reference)
    return xml_send.encode('utf-8')
Example #27
0
def _render(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), "templates")
    xml_send = render_xml(path, "%s.xml" % method, True, **kwargs)

    reference = ""
    if method in ("RecepcionarLoteRpsV3", "RecepcionarLoteRpsSincronoV3"):
        reference = "rps%s" % kwargs["nfse"]["lista_rps"][0]["numero"]
    elif method == "CancelarNfseV3":
        reference = "C%s" % kwargs["cancelamento"]["numero_nfse"]

    signer = Assinatura(certificado.pfx, certificado.password)
    xml_send = signer.assina_xml(xml_send, reference)
    return xml_send
Example #28
0
def sign_rps(path, certificado, **kwargs):
    if "nfse" in kwargs:
        lote = ""
        for item in kwargs["nfse"]["lista_rps"]:
            data = {"rps": item}
            xml_rps = render_xml(path, "Rps.xml", True, **data)

            signer = Assinatura(certificado.pfx, certificado.password)
            lote += signer.assina_xml(
                xml_rps, f"rps:{item.get('numero')}{item.get('serie')}", getchildren=True
            )
        return lote
    return ""
Example #29
0
def _render(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), "templates")
    xml_send = render_xml(path, "%s.xml" % method, True, **kwargs)

    reference = ""
    if method == "GerarNfse":
        reference = "r%s" % kwargs["rps"]["numero"]
    elif method == "CancelarNfse":
        reference = "Cancelamento_NF%s" % kwargs["cancelamento"]["numero_nfse"]

    signer = Assinatura(certificado.pfx, certificado.password)
    xml_send = signer.assina_xml(xml_send, reference)
    return xml_send.encode("utf-8")
Example #30
0
def _send(method, **kwargs):
    if kwargs['ambiente'] == 'producao':
        base_url = 'http://sistemas.pmp.sp.gov.br/semfi/simpliss/ws_nfse/nfseservice.svc'  # noqa
    else:
        base_url = 'http://wshomologacao.simplissweb.com.br/nfseservice.svc'  # noqa

    base_url = 'http://wshomologacao.simplissweb.com.br/nfseservice.svc'
    xml_send = kwargs["xml"].replace('<?xml version="1.0"?>', '')
    path = os.path.join(os.path.dirname(__file__), 'templates')
    soap = render_xml(path, 'SoapRequest.xml', False, soap_body=xml_send)

    act = 'http://www.sistema.com.br/Sistema.Ws.Nfse/INfseService/%s' % method

    client = HttpClient(base_url)
    response = client.post_soap(soap, act)

    response, obj = sanitize_response(response)
    return {'sent_xml': xml_send, 'received_xml': response, 'object': obj}
Example #31
0
def _send(method, **kwargs):
    if kwargs["ambiente"] == "producao":
        base_url = "http://sistemas.pmp.sp.gov.br/semfi/simpliss/ws_nfse/nfseservice.svc"  # noqa
    else:
        base_url = "http://wshomologacao.simplissweb.com.br/nfseservice.svc"  # noqa

    base_url = "http://wshomologacao.simplissweb.com.br/nfseservice.svc"
    xml_send = kwargs["xml"]
    path = os.path.join(os.path.dirname(__file__), "templates")
    soap = render_xml(path, "SoapRequest.xml", False, soap_body=xml_send)

    act = "http://www.sistema.com.br/Sistema.Ws.Nfse/INfseService/%s" % method

    client = HttpClient(base_url)
    response = client.post_soap(soap, act)

    response, obj = sanitize_response(response)
    return {"sent_xml": xml_send, "received_xml": response, "object": obj}
Example #32
0
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)

    modelo = xmlElem_send.find(".//{http://www.portalfiscal.inf.br/nfe}mod")
    modelo = modelo.text if modelo is not None else '55'

    if sign:
        # Caso for autorização temos que adicionar algumas tags tipo
        # cEan, cEANTrib porque o governo sempre complica e não segue padrão
        if method == 'NfeAutorizacao':
            xmlElem_send = _add_required_node(xmlElem_send)

        signer = Assinatura(certificado.pfx, certificado.password)
        if method == 'NfeInutilizacao':
            xml_send = signer.assina_xml(xmlElem_send, kwargs['obj']['id'])
        if method == 'NfeAutorizacao':
            xml_send = signer.assina_xml(xmlElem_send,
                                         kwargs['NFes'][0]['infNFe']['Id'])
            if modelo == '65' and 'validate' in kwargs:
                #xml_send = _add_qrCode(xml_send, **kwargs)
                #if 'validate' in kwargs:
                erros = valida_nfe(xml_send)
                if erros:
                    raise NFeValidationException('Erro ao validar NFe',
                                                 erros=erros,
                                                 sent_xml=xml_send)
        elif method == 'RecepcaoEventoCancelamento':
            xml_send = signer.assina_xml(xmlElem_send,
                                         kwargs['eventos'][0]['Id'])

        if method == 'RecepcaoEvento':
            xml_send = signer.assina_xml(xmlElem_send,
                                         kwargs['eventos'][0]['Id'])
        elif method == 'RecepcaoEventoManifesto':
            xml_send = signer.assina_xml(xmlElem_send,
                                         kwargs['manifesto']['identificador'])

    else:
        xml_send = etree.tostring(xmlElem_send, encoding=str)

    return xml_send
Example #33
0
def _send(certificado, method, **kwargs):
    base_url = ''
    if kwargs['ambiente'] == 'producao':
        base_url = 'https://nfe.etransparencia.com.br/rj.petropolis/webservice/aws_nfe.aspx'  # noqa
    else:
        base_url = 'https://nfehomologacao.etransparencia.com.br/rj.petropolis/webservice/aws_nfe.aspx'  # noqa

    xml_send = kwargs["xml"]
    path = os.path.join(os.path.dirname(__file__), 'templates')
    soap = render_xml(path, 'SoapRequest.xml', False, soap_body=xml_send)

    client = HttpClient(base_url)
    response = client.post_soap(soap, 'NFeaction/AWS_NFE.%s' % method)

    response, obj = sanitize_response(response)
    return {
        'sent_xml': xml_send,
        'received_xml': response,
        'object': obj
    }
Example #34
0
def _render(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), "templates")
    parser = etree.XMLParser(
        remove_blank_text=True, remove_comments=True, strip_cdata=False
    )

    lote = ""
    referencia = ""
    if method == "RecepcionarLoteRps":
        referencia = "lote"
        lote = sign_rps(path, certificado, **kwargs)

    kwargs["lote"] = lote
    xml_send = render_xml(path, "%s.xml" % method, False, **kwargs)

    signer = Assinatura(certificado.pfx, certificado.password)

    xml_send = signer.assina_xml(etree.fromstring(
        xml_send, parser=parser), f"{referencia}", getchildren=True)
    return xml_send
Example #35
0
def _render(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), 'templates')
    xml_send = render_xml(path, '%s.xml' % method, True, **kwargs)
    if method in ('RecepcionarLoteRps','CancelarNfse'):
        reference = ''
        if method == 'RecepcionarLoteRps':
            reference = '%s' % kwargs['nfse']['lista_rps'][0]['numero']
        signer = Assinatura(certificado.pfx, certificado.password)
        xml_send = signer.assina_xml(xml_send, reference)
#         xml_send = etree.tostring(xml_send)
        if method == 'CancelarNfse':
            xml_send = etree.fromstring(xml_send)
            Signature = xml_send.find(".//{http://www.w3.org/2000/09/xmldsig#}Signature")
            Pedido = xml_send.find(".//{http://www.betha.com.br/e-nota-contribuinte-ws}Pedido")
            if Signature:
                Pedido.append(Signature)
            xml_send = etree.tostring(xml_send)
    else:
        xml_send = etree.tostring(xml_send)
    return xml_send
Example #36
0
def _send(method, **kwargs):
    if kwargs['ambiente'] == 'producao':
        base_url = 'http://sistemas.pmp.sp.gov.br/semfi/simpliss/ws_nfse/nfseservice.svc'  # noqa
    else:
        base_url = 'http://wshomologacao.simplissweb.com.br/nfseservice.svc'  # noqa

    base_url = 'http://wshomologacao.simplissweb.com.br/nfseservice.svc'
    xml_send = kwargs["xml"].replace('<?xml version="1.0"?>', '')
    path = os.path.join(os.path.dirname(__file__), 'templates')
    soap = render_xml(path, 'SoapRequest.xml', False, soap_body=xml_send)

    act = 'http://www.sistema.com.br/Sistema.Ws.Nfse/INfseService/%s' % method

    client = HttpClient(base_url)
    response = client.post_soap(soap, act)

    response, obj = sanitize_response(response)
    return {
        'sent_xml': xml_send,
        'received_xml': response,
        'object': obj
    }
Example #37
0
def _render_xml(certificado, method, **kwargs):
    path = os.path.join(os.path.dirname(__file__), 'templates')
    xml_send = render_xml(path, '%s.xml' % method, True, **kwargs)
    xml_send = etree.tostring(xml_send)

    return xml_send