|
|
|
@ -6,7 +6,7 @@ from pynfe.entidades import NotaFiscal |
|
|
|
from pynfe.utils import etree, so_numeros, obter_municipio_por_codigo, \ |
|
|
|
obter_pais_por_codigo, obter_municipio_e_codigo, \ |
|
|
|
formatar_decimal, remover_acentos, obter_uf_por_codigo, obter_codigo_por_municipio |
|
|
|
from pynfe.utils.flags import CODIGOS_ESTADOS, VERSAO_PADRAO, NAMESPACE_NFE |
|
|
|
from pynfe.utils.flags import CODIGOS_ESTADOS, VERSAO_PADRAO, NAMESPACE_NFE, NAMESPACE_BETHA |
|
|
|
|
|
|
|
class Serializacao(object): |
|
|
|
"""Classe abstrata responsavel por fornecer as funcionalidades basicas para |
|
|
|
@ -576,6 +576,99 @@ class SerializacaoXML(Serializacao): |
|
|
|
else: |
|
|
|
return raiz |
|
|
|
|
|
|
|
class SerializacaoNfse(Serializacao): |
|
|
|
|
|
|
|
def exportar(self): |
|
|
|
pass |
|
|
|
|
|
|
|
def importar(self): |
|
|
|
pass |
|
|
|
|
|
|
|
def _serializar_emitente(self, emitente, tag_raiz='Prestador', retorna_string=True): |
|
|
|
raiz = etree.Element(tag_raiz) |
|
|
|
documento = etree.SubElement(raiz, 'CpfCnpj') |
|
|
|
etree.SubElement(documento, 'Cnpj').text = emitente.cnpj |
|
|
|
etree.SubElement(raiz, 'InscricaoMunicipal').text = emitente.inscricao_municipal |
|
|
|
|
|
|
|
if retorna_string: |
|
|
|
return etree.tostring(raiz, encoding="unicode", pretty_print=True) |
|
|
|
else: |
|
|
|
return raiz |
|
|
|
|
|
|
|
def _serializar_cliente(self, cliente, tag_raiz='Tomador', retorna_string=True): |
|
|
|
raiz = etree.Element(tag_raiz) |
|
|
|
identificacao = etree.SubElement(raiz, 'IdentificacaoTomador') |
|
|
|
documento = etree.SubElement(identificacao, 'CpfCnpj') |
|
|
|
etree.SubElement(documento, cliente.tipo_documento).text = cliente.numero_documento # Apenas Cnpj ?? |
|
|
|
etree.SubElement(identificacao, 'InscricaoMunicipal').text = cliente.inscricao_municipal # obrigatório?? |
|
|
|
etree.SubElement(raiz, 'RazaoSocial').text = cliente.razao_social |
|
|
|
endereco = etree.SubElement(raiz, 'Endereco') |
|
|
|
etree.SubElement(endereco, 'Endereco').text = cliente.endereco_logradouro |
|
|
|
etree.SubElement(endereco, 'Numero').text = cliente.endereco_numero |
|
|
|
if cliente.endereco_complemento: |
|
|
|
etree.SubElement(endereco, 'Complemento').text = cliente.endereco_complemento |
|
|
|
etree.SubElement(endereco, 'Bairro').text = cliente.endereco_bairro |
|
|
|
etree.SubElement(endereco, 'CodigoMunicipio').text = obter_codigo_por_municipio( |
|
|
|
cliente.endereco_municipio, cliente.endereco_uf) |
|
|
|
etree.SubElement(endereco, 'Uf').text = cliente.endereco_uf |
|
|
|
etree.SubElement(endereco, 'CodigoPais').text = cliente.endereco_pais |
|
|
|
etree.SubElement(endereco, 'Cep').text = so_numeros(cliente.endereco_cep) |
|
|
|
contato = etree.SubElement(raiz, 'Contato') |
|
|
|
etree.SubElement(contato, 'Telefone').text = cliente.endereco_telefone |
|
|
|
etree.SubElement(contato, 'Email').text = cliente.email |
|
|
|
|
|
|
|
if retorna_string: |
|
|
|
return etree.tostring(raiz, encoding="unicode", pretty_print=True) |
|
|
|
else: |
|
|
|
return raiz |
|
|
|
|
|
|
|
def _serializar_servico(self, servico, tag_raiz='Servico', retorna_string=True): |
|
|
|
raiz = etree.Element(tag_raiz) |
|
|
|
valores = etree.SubElement(raiz, 'Valores') |
|
|
|
etree.SubElement(valores, 'ValorServicos').text = str('{:.2f}').format(servico.valor_servico) |
|
|
|
etree.SubElement(raiz, 'IssRetido').text = str('{:.2f}').format(servico.iss_retido) |
|
|
|
#etree.SubElement(raiz, 'ResponsavelRetencao').text = '' |
|
|
|
etree.SubElement(raiz, 'ItemListaServico').text = servico.item_lista |
|
|
|
#etree.SubElement(raiz, 'CodigoCnae').text = '' |
|
|
|
#etree.SubElement(raiz, 'CodigoTributacaoMunicipio').text = '' |
|
|
|
etree.SubElement(raiz, 'Discriminacao').text = servico.discriminacao |
|
|
|
etree.SubElement(raiz, 'CodigoMunicipio').text = servico.codigo_municipio |
|
|
|
#etree.SubElement(raiz, 'CodigoPais').text = '' |
|
|
|
etree.SubElement(raiz, 'ExigibilidadeISS').text = str(servico.exigibilidade) |
|
|
|
etree.SubElement(raiz, 'MunicipioIncidencia').text = servico.codigo_municipio |
|
|
|
#etree.SubElement(raiz, 'NumeroProcesso').text = '' |
|
|
|
|
|
|
|
if retorna_string: |
|
|
|
return etree.tostring(raiz, encoding="unicode", pretty_print=True) |
|
|
|
else: |
|
|
|
return raiz |
|
|
|
|
|
|
|
def _serializar_gerar(self, nfse, tag_raiz='GerarNfseEnvio', retorna_string=False): |
|
|
|
|
|
|
|
if nfse.autorizador == 'betha': |
|
|
|
raiz = etree.Element(tag_raiz, xmlns=NAMESPACE_BETHA) |
|
|
|
# TODO - implementar outros sistemas autorizadores |
|
|
|
else: |
|
|
|
raiz = etree.Element(tag_raiz) |
|
|
|
rps = etree.SubElement(raiz, 'Rps') |
|
|
|
info = etree.SubElement(rps, 'InfDeclaracaoPrestacaoServico', Id=nfse.identificador) |
|
|
|
etree.SubElement(info, 'Competencia').text = nfse.data_emissao.strftime('%Y-%m-%d') |
|
|
|
|
|
|
|
# Servico |
|
|
|
info.append(self._serializar_servico(nfse.servico, retorna_string=False)) |
|
|
|
# Emitente/Prestador |
|
|
|
info.append(self._serializar_emitente(nfse.emitente, retorna_string=False)) |
|
|
|
# Cliente/Tomador |
|
|
|
info.append(self._serializar_cliente(nfse.cliente, retorna_string=False)) |
|
|
|
|
|
|
|
etree.SubElement(info, 'OptanteSimplesNacional').text = str(nfse.simples) # 1-Sim; 2-Não |
|
|
|
etree.SubElement(info, 'IncentivoFiscal').text = str(nfse.incentivo) # 1-Sim; 2-Não |
|
|
|
|
|
|
|
if retorna_string: |
|
|
|
return etree.tostring(raiz, encoding="unicode", pretty_print=True) |
|
|
|
else: |
|
|
|
return raiz |
|
|
|
|
|
|
|
class SerializacaoPipes(Serializacao): |
|
|
|
"""Serialização utilizada pela SEFAZ-SP para a importação de notas.""" |
|
|
|
|
|
|
|
|