@ -1,12 +1,8 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import time
import time
try :
set
except :
from sets import Set as set
from pynfe.entidades import Emitente , Cliente , Produto , Transportadora , NotaFiscal
from pynfe.excecoes import NenhumObjetoEncontrado , MuitosObjetosEncontrados
from pynfe.entidades import NotaFiscal
from pynfe.utils import etree , so_numeros , obter_municipio_por_codigo , \
from pynfe.utils import etree , so_numeros , obter_municipio_por_codigo , \
obter_pais_por_codigo , obter_municipio_e_codigo , \
obter_pais_por_codigo , obter_municipio_e_codigo , \
formatar_decimal , safe_str , obter_uf_por_codigo , obter_codigo_por_municipio
formatar_decimal , safe_str , obter_uf_por_codigo , obter_codigo_por_municipio
@ -101,14 +97,15 @@ class SerializacaoXML(Serializacao):
else :
else :
return raiz
return raiz
def _serializar_cliente ( self , cliente , tag_raiz = ' dest ' , retorna_string = True ) :
def _serializar_cliente ( self , cliente , modelo , tag_raiz = ' dest ' , retorna_string = True ) :
raiz = etree . Element ( tag_raiz )
raiz = etree . Element ( tag_raiz )
# Dados do cliente
# Dados do cliente (distinatario)
etree . SubElement ( raiz , cliente . tipo_documento ) . text = so_numeros ( cliente . numero_documento )
etree . SubElement ( raiz , cliente . tipo_documento ) . text = so_numeros ( cliente . numero_documento )
etree . SubElement ( raiz , ' xNome ' ) . text = cliente . razao_social
etree . SubElement ( raiz , ' xNome ' ) . text = cliente . razao_social
etree . SubElement ( raiz , ' IE ' ) . text = cliente . inscricao_estadual
# nfc-e nao possui IE mesmo que seja uma empresa
if modelo == 55 :
etree . SubElement ( raiz , ' IE ' ) . text = cliente . inscricao_estadual
# Endereço
# Endereço
endereco = etree . SubElement ( raiz , ' enderDest ' )
endereco = etree . SubElement ( raiz , ' enderDest ' )
etree . SubElement ( endereco , ' xLgr ' ) . text = cliente . endereco_logradouro
etree . SubElement ( endereco , ' xLgr ' ) . text = cliente . endereco_logradouro
@ -250,7 +247,17 @@ class SerializacaoXML(Serializacao):
horário de verão serão - 01 : 00 , - 02 : 00 e - 03 : 00. Exemplo : " 2010-08-19T13:00:15-03:00 " .
horário de verão serão - 01 : 00 , - 02 : 00 e - 03 : 00. Exemplo : " 2010-08-19T13:00:15-03:00 " .
"""
"""
etree . SubElement ( ide , ' tpNF ' ) . text = str ( nota_fiscal . tipo_documento ) # 0=entrada 1=saida
etree . SubElement ( ide , ' tpNF ' ) . text = str ( nota_fiscal . tipo_documento ) # 0=entrada 1=saida
etree . SubElement ( ide , ' idDest ' ) . text = str ( 1 ) # Identificador de local de destino da operação 1=Operação interna;2=Operação interestadual;3=Operação com exterior.
""" nfce suporta apenas operação interna
Identificador de local de destino da operação 1 = Operação interna ; 2 = Operação interestadual ; 3 = Operação com exterior .
"""
if nota_fiscal . modelo == 65 :
etree . SubElement ( ide , ' idDest ' ) . text = str ( 1 )
etree . SubElement ( ide , ' indPres ' ) . text = str ( 1 )
etree . SubElement ( ide , ' indFinal ' ) . text = str ( 1 )
else :
etree . SubElement ( ide , ' idDest ' ) . text = str ( nota_fiscal . indicador_destino )
etree . SubElement ( ide , ' indPres ' ) . text = str ( nota_fiscal . indicador_presencial )
etree . SubElement ( ide , ' indFinal ' ) . text = str ( nota_fiscal . cliente_final )
etree . SubElement ( ide , ' cMunFG ' ) . text = nota_fiscal . municipio
etree . SubElement ( ide , ' cMunFG ' ) . text = nota_fiscal . municipio
etree . SubElement ( ide , ' tpImp ' ) . text = str ( nota_fiscal . tipo_impressao_danfe )
etree . SubElement ( ide , ' tpImp ' ) . text = str ( nota_fiscal . tipo_impressao_danfe )
etree . SubElement ( ide , ' tpEmis ' ) . text = str ( nota_fiscal . forma_emissao )
etree . SubElement ( ide , ' tpEmis ' ) . text = str ( nota_fiscal . forma_emissao )
@ -258,14 +265,16 @@ class SerializacaoXML(Serializacao):
etree . SubElement ( ide , ' tpAmb ' ) . text = str ( self . _ambiente )
etree . SubElement ( ide , ' tpAmb ' ) . text = str ( self . _ambiente )
etree . SubElement ( ide , ' finNFe ' ) . text = str ( nota_fiscal . finalidade_emissao )
etree . SubElement ( ide , ' finNFe ' ) . text = str ( nota_fiscal . finalidade_emissao )
etree . SubElement ( ide , ' procEmi ' ) . text = str ( nota_fiscal . processo_emissao )
etree . SubElement ( ide , ' procEmi ' ) . text = str ( nota_fiscal . processo_emissao )
etree . SubElement ( ide , ' verProc ' ) . text = ' %s %s ' % ( self . _nome_aplicacao ,
nota_fiscal . versao_processo_emissao )
etree . SubElement ( ide , ' verProc ' ) . text = ' %s %s ' % ( self . _nome_aplicacao , nota_fiscal . versao_processo_emissao )
### CONTINGENCIA ###
#etree.SubElement(ide, 'dhCont').text = '' # Data e Hora da entrada em contingência AAAA-MM-DDThh:mm:ssTZD
#etree.SubElement(ide, 'xJust').text = '' # Justificativa da entrada em contingência (min 20, max 256 caracteres)
# Emitente
# Emitente
raiz . append ( self . _serializar_emitente ( nota_fiscal . emitente , retorna_string = False ) )
raiz . append ( self . _serializar_emitente ( nota_fiscal . emitente , retorna_string = False ) )
# Destinatário
# Destinatário
raiz . append ( self . _serializar_cliente ( nota_fiscal . cliente , retorna_string = False ) )
raiz . append ( self . _serializar_cliente ( nota_fiscal . cliente , modelo = nota_fiscal . modelo , retorna_string = False ) )
# Retirada
# Retirada
if nota_fiscal . retirada :
if nota_fiscal . retirada :
@ -301,50 +310,55 @@ class SerializacaoXML(Serializacao):
etree . SubElement ( icms_total , ' vFrete ' ) . text = str ( nota_fiscal . totais_icms_total_frete )
etree . SubElement ( icms_total , ' vFrete ' ) . text = str ( nota_fiscal . totais_icms_total_frete )
etree . SubElement ( icms_total , ' vSeg ' ) . text = str ( nota_fiscal . totais_icms_total_seguro )
etree . SubElement ( icms_total , ' vSeg ' ) . text = str ( nota_fiscal . totais_icms_total_seguro )
etree . SubElement ( icms_total , ' vDesc ' ) . text = str ( nota_fiscal . totais_icms_total_desconto )
etree . SubElement ( icms_total , ' vDesc ' ) . text = str ( nota_fiscal . totais_icms_total_desconto )
etree . SubElement ( icms_total , ' vII ' ) . text = str ( nota_fiscal . totais_icms_total_ii )
etree . SubElement ( icms_total , ' vIPI ' ) . text = str ( nota_fiscal . totais_icms_total_ipi )
etree . SubElement ( icms_total , ' vPIS ' ) . text = str ( nota_fiscal . totais_icms_pis )
etree . SubElement ( icms_total , ' vCOFINS ' ) . text = str ( nota_fiscal . totais_icms_cofins )
etree . SubElement ( icms_total , ' vOutro ' ) . text = str ( nota_fiscal . totais_icms_outras_despesas_acessorias )
etree . SubElement ( icms_total , ' vOutro ' ) . text = str ( nota_fiscal . totais_icms_outras_despesas_acessorias )
etree . SubElement ( icms_total , ' vNF ' ) . text = str ( nota_fiscal . totais_icms_total_nota )
etree . SubElement ( icms_total , ' vNF ' ) . text = str ( nota_fiscal . totais_icms_total_nota )
# Transporte
transp = etree . SubElement ( raiz , ' transp ' )
etree . SubElement ( transp , ' modFrete ' ) . text = str ( nota_fiscal . transporte_modalidade_frete )
# Transportadora
if nota_fiscal . transporte_transportadora :
transp . append ( self . _serializar_transportadora (
nota_fiscal . transporte_transportadora ,
retorna_string = False ,
) )
# Veículo
veiculo = etree . SubElement ( transp , ' veicTransp ' )
etree . SubElement ( veiculo , ' placa ' ) . text = nota_fiscal . transporte_veiculo_placa
etree . SubElement ( veiculo , ' UF ' ) . text = nota_fiscal . transporte_veiculo_uf
etree . SubElement ( veiculo , ' RNTC ' ) . text = nota_fiscal . transporte_veiculo_rntc
# Reboque
reboque = etree . SubElement ( transp , ' reboque ' )
etree . SubElement ( reboque , ' placa ' ) . text = nota_fiscal . transporte_reboque_placa
etree . SubElement ( reboque , ' UF ' ) . text = nota_fiscal . transporte_reboque_uf
etree . SubElement ( reboque , ' RNTC ' ) . text = nota_fiscal . transporte_reboque_rntc
# Volumes
for volume in nota_fiscal . transporte_volumes :
vol = etree . SubElement ( transp , ' vol ' )
etree . SubElement ( vol , ' qVol ' ) . text = str ( volume . quantidade )
etree . SubElement ( vol , ' esp ' ) . text = volume . especie
etree . SubElement ( vol , ' marca ' ) . text = volume . marca
etree . SubElement ( vol , ' nVol ' ) . text = volume . numeracao
etree . SubElement ( vol , ' pesoL ' ) . text = str ( volume . peso_liquido )
etree . SubElement ( vol , ' pesoB ' ) . text = str ( volume . peso_bruto )
# Lacres
lacres = etree . SubElement ( vol , ' lacres ' )
for lacre in volume . lacres :
etree . SubElement ( lacres , ' nLacre ' ) . text = lacre . numero_lacre
# Apenas NF-e
if nota_fiscal . modelo == 55 :
# Tributos
etree . SubElement ( icms_total , ' vIPI ' ) . text = str ( nota_fiscal . totais_icms_total_ipi )
etree . SubElement ( icms_total , ' vPIS ' ) . text = str ( nota_fiscal . totais_icms_pis )
etree . SubElement ( icms_total , ' vCOFINS ' ) . text = str ( nota_fiscal . totais_icms_cofins )
etree . SubElement ( icms_total , ' vII ' ) . text = str ( nota_fiscal . totais_icms_total_ii )
# Transporte
transp = etree . SubElement ( raiz , ' transp ' )
etree . SubElement ( transp , ' modFrete ' ) . text = str ( nota_fiscal . transporte_modalidade_frete )
# Transportadora
if nota_fiscal . transporte_transportadora :
transp . append ( self . _serializar_transportadora (
nota_fiscal . transporte_transportadora ,
retorna_string = False ,
) )
# Veículo
veiculo = etree . SubElement ( transp , ' veicTransp ' )
etree . SubElement ( veiculo , ' placa ' ) . text = nota_fiscal . transporte_veiculo_placa
etree . SubElement ( veiculo , ' UF ' ) . text = nota_fiscal . transporte_veiculo_uf
etree . SubElement ( veiculo , ' RNTC ' ) . text = nota_fiscal . transporte_veiculo_rntc
# Reboque
reboque = etree . SubElement ( transp , ' reboque ' )
etree . SubElement ( reboque , ' placa ' ) . text = nota_fiscal . transporte_reboque_placa
etree . SubElement ( reboque , ' UF ' ) . text = nota_fiscal . transporte_reboque_uf
etree . SubElement ( reboque , ' RNTC ' ) . text = nota_fiscal . transporte_reboque_rntc
# Volumes
for volume in nota_fiscal . transporte_volumes :
vol = etree . SubElement ( transp , ' vol ' )
etree . SubElement ( vol , ' qVol ' ) . text = str ( volume . quantidade )
etree . SubElement ( vol , ' esp ' ) . text = volume . especie
etree . SubElement ( vol , ' marca ' ) . text = volume . marca
etree . SubElement ( vol , ' nVol ' ) . text = volume . numeracao
etree . SubElement ( vol , ' pesoL ' ) . text = str ( volume . peso_liquido )
etree . SubElement ( vol , ' pesoB ' ) . text = str ( volume . peso_bruto )
# Lacres
lacres = etree . SubElement ( vol , ' lacres ' )
for lacre in volume . lacres :
etree . SubElement ( lacres , ' nLacre ' ) . text = lacre . numero_lacre
# Informações adicionais
# Informações adicionais
info_ad = etree . SubElement ( raiz , ' infAdic ' )
info_ad = etree . SubElement ( raiz , ' infAdic ' )