Skip to content

Commit

Permalink
Adicionada validação do esquema de xml da NFe
Browse files Browse the repository at this point in the history
  • Loading branch information
martini97 committed Jan 30, 2017
1 parent 1df7a4b commit 41e53fc
Show file tree
Hide file tree
Showing 8 changed files with 6,808 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pytrustnfe/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# © 2016 Alessandro Fernandes Martini, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


class NFeValidationException(ValueError):
"""Exceção para erro na validação do esquema da NFe"""

def __init__(self, message, *args, **kwargs):
self.erros = kwargs['erros']
self.sent_xml = kwargs['sent_xml']
super(NFeValidationException, self).__init__(message, *args, **kwargs)
8 changes: 8 additions & 0 deletions pytrustnfe/nfe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from pytrustnfe.utils import CabecalhoSoap
from pytrustnfe.utils import gerar_chave, ChaveNFe
from pytrustnfe.Servidores import localizar_url, localizar_qrcode
from pytrustnfe.xml.validate import valida_nfe
from pytrustnfe.exceptions import NFeValidationException


def _build_header(method, **kwargs):
Expand Down Expand Up @@ -149,6 +151,12 @@ def _send(certificado, method, sign, **kwargs):
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'])
Expand Down
9 changes: 9 additions & 0 deletions pytrustnfe/xml/schemas/enviNFe_v3.10.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="leiauteNFe_v3.10.xsd"/>
<xs:element name="enviNFe" type="TEnviNFe">
<xs:annotation>
<xs:documentation>Schema XML de validação do Pedido de Concessão de Autorização da Nota Fiscal Eletrônica</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
6,060 changes: 6,060 additions & 0 deletions pytrustnfe/xml/schemas/leiauteNFe_v3.10.xsd

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions pytrustnfe/xml/schemas/nfe_v3.10.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/nfe" targetNamespace="http://www.portalfiscal.inf.br/nfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="leiauteNFe_v3.10.xsd"/>
<xs:element name="NFe" type="TNFe">
<xs:annotation>
<xs:documentation>Nota Fiscal Eletrônica</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>

0 comments on commit 41e53fc

Please sign in to comment.