@ -90,6 +90,9 @@ class SerializacaoXML(Serializacao):
raiz = etree . Element ( tag_raiz )
raiz = etree . Element ( tag_raiz )
# Dados do emitente
# Dados do emitente
if len ( so_numeros ( emitente . cnpj ) ) == 11 :
etree . SubElement ( raiz , ' CPF ' ) . text = so_numeros ( emitente . cnpj )
else :
etree . SubElement ( raiz , ' CNPJ ' ) . text = so_numeros ( emitente . cnpj )
etree . SubElement ( raiz , ' CNPJ ' ) . text = so_numeros ( emitente . cnpj )
etree . SubElement ( raiz , ' xNome ' ) . text = emitente . razao_social
etree . SubElement ( raiz , ' xNome ' ) . text = emitente . razao_social
etree . SubElement ( raiz , ' xFant ' ) . text = emitente . nome_fantasia
etree . SubElement ( raiz , ' xFant ' ) . text = emitente . nome_fantasia
@ -222,7 +225,10 @@ class SerializacaoXML(Serializacao):
etree . SubElement ( prod , ' NCM ' ) . text = produto_servico . ncm
etree . SubElement ( prod , ' NCM ' ) . text = produto_servico . ncm
# Codificação opcional que detalha alguns NCM. Formato: duas letras maiúsculas e 4 algarismos.
# Codificação opcional que detalha alguns NCM. Formato: duas letras maiúsculas e 4 algarismos.
# Se a mercadoria se enquadrar em mais de uma codificação, informar até 8 codificações principais.
# Se a mercadoria se enquadrar em mais de uma codificação, informar até 8 codificações principais.
#etree.SubElement(prod, 'NVE').text = ''
# etree.SubElement(prod, 'NVE').text = ''
# etree.SubElement(prod, 'CEST').text = produto_service.cest
if produto_servico . cbenef :
etree . SubElement ( prod , ' cBenef ' ) . text = produto_servico . cbenef
etree . SubElement ( prod , ' CFOP ' ) . text = produto_servico . cfop
etree . SubElement ( prod , ' CFOP ' ) . text = produto_servico . cfop
etree . SubElement ( prod , ' uCom ' ) . text = produto_servico . unidade_comercial
etree . SubElement ( prod , ' uCom ' ) . text = produto_servico . unidade_comercial
etree . SubElement ( prod , ' qCom ' ) . text = str ( produto_servico . quantidade_comercial or 0 )
etree . SubElement ( prod , ' qCom ' ) . text = str ( produto_servico . quantidade_comercial or 0 )
@ -287,6 +293,11 @@ class SerializacaoXML(Serializacao):
icms_item = etree . SubElement ( icms , ' ICMSSN ' + produto_servico . icms_modalidade )
icms_item = etree . SubElement ( icms , ' ICMSSN ' + produto_servico . icms_modalidade )
etree . SubElement ( icms_item , ' orig ' ) . text = str ( produto_servico . icms_origem )
etree . SubElement ( icms_item , ' orig ' ) . text = str ( produto_servico . icms_origem )
etree . SubElement ( icms_item , ' CSOSN ' ) . text = produto_servico . icms_csosn
etree . SubElement ( icms_item , ' CSOSN ' ) . text = produto_servico . icms_csosn
elif produto_servico . icms_modalidade == ' 51 ' :
icms_item = etree . SubElement ( icms , ' ICMS ' + produto_servico . icms_modalidade )
etree . SubElement ( icms_item , ' orig ' ) . text = str ( produto_servico . icms_origem )
etree . SubElement ( icms_item , ' CST ' ) . text = ' 51 '
etree . SubElement ( icms_item , ' modBC ' ) . text = str ( produto_servico . icms_modalidade_determinacao_bc )
else :
else :
### OUTROS TIPOS DE ICMS (00,10,20)
### OUTROS TIPOS DE ICMS (00,10,20)
icms_item = etree . SubElement ( icms , ' ICMS ' + produto_servico . icms_modalidade )
icms_item = etree . SubElement ( icms , ' ICMS ' + produto_servico . icms_modalidade )
@ -329,12 +340,18 @@ class SerializacaoXML(Serializacao):
else :
else :
raise NotImplementedError
raise NotImplementedError
# ipi
# ipi
# ipi = etree.SubElement(imposto, 'IPI')
# etree.SubElement(ipi, 'clEnq') = produto_servico.ipi_classe_enquadramento # Preenchimento conforme Atos Normativos editados pela Receita Federal (Observação 2)
# ipint = etree.SubElement(ipi, 'IPINT')
# # 01=Entrada tributada com alíquota zero 02=Entrada isenta 03=Entrada não-tributada 04=Entrada imune 05=Entrada com suspensão
# # 51=Saída tributada com alíquota zero 52=Saída isenta 53=Saída não-tributada 54=Saída imune 55=Saída com suspensão
# etree.SubElement(ipint, 'CST') = produto_servico.ipi_codigo_enquadramento
ipint_lista = ( ' 01 ' , ' 02 ' , ' 03 ' , ' 04 ' , ' 05 ' , ' 51 ' , ' 52 ' , ' 53 ' , ' 54 ' , ' 55 ' )
if produto_servico . ipi_codigo_enquadramento in ipint_lista :
ipi = etree . SubElement ( imposto , ' IPI ' )
# Preenchimento conforme Atos Normativos editados pela Receita Federal (Observação 2)
etree . SubElement ( ipi , ' cEnq ' ) . text = produto_servico . ipi_classe_enquadramento
if produto_servico . ipi_classe_enquadramento == ' ' :
etree . SubElement ( ipi , ' cEnq ' ) . text = ' 999 '
ipint = etree . SubElement ( ipi , ' IPINT ' )
# 01=Entrada tributada com alíquota zero 02=Entrada isenta 03=Entrada não-tributada 04=Entrada imune 05=Entrada com suspensão
# 51=Saída tributada com alíquota zero 52=Saída isenta 53=Saída não-tributada 54=Saída imune 55=Saída com suspensão
etree . SubElement ( ipint , ' CST ' ) . text = produto_servico . ipi_codigo_enquadramento
# apenas nfe
# apenas nfe
if modelo == 55 :
if modelo == 55 :
@ -670,8 +687,10 @@ class SerializacaoXML(Serializacao):
e = etree . SubElement ( raiz , ' infEvento ' , Id = evento . identificador )
e = etree . SubElement ( raiz , ' infEvento ' , Id = evento . identificador )
etree . SubElement ( e , ' cOrgao ' ) . text = CODIGOS_ESTADOS [ evento . uf . upper ( ) ]
etree . SubElement ( e , ' cOrgao ' ) . text = CODIGOS_ESTADOS [ evento . uf . upper ( ) ]
etree . SubElement ( e , ' tpAmb ' ) . text = str ( self . _ambiente )
etree . SubElement ( e , ' tpAmb ' ) . text = str ( self . _ambiente )
etree . SubElement ( e , ' CNPJ ' ) . text = evento . cnpj # Empresas somente terão CNPJ
#etree.SubElement(e, 'CPF').text = ''
if len ( so_numeros ( evento . cnpj ) ) == 11 :
etree . SubElement ( e , ' CPF ' ) . text = evento . cnpj
else :
etree . SubElement ( e , ' CNPJ ' ) . text = evento . cnpj
etree . SubElement ( e , ' chNFe ' ) . text = evento . chave
etree . SubElement ( e , ' chNFe ' ) . text = evento . chave
etree . SubElement ( e , ' dhEvento ' ) . text = evento . data_emissao . strftime ( ' % Y- % m- %d T % H: % M: % S ' ) + tz
etree . SubElement ( e , ' dhEvento ' ) . text = evento . data_emissao . strftime ( ' % Y- % m- %d T % H: % M: % S ' ) + tz
etree . SubElement ( e , ' tpEvento ' ) . text = evento . tp_evento
etree . SubElement ( e , ' tpEvento ' ) . text = evento . tp_evento
@ -757,10 +776,10 @@ class SerializacaoQrcode(object):
elif uf . upper ( ) == ' SP ' :
elif uf . upper ( ) == ' SP ' :
if tpamb == ' 1 ' :
if tpamb == ' 1 ' :
qrcode = NFCE [ uf . upper ( ) ] [ ' HTTPS ' ] + ' www. ' + NFCE [ uf . upper ( ) ] [ ' QR ' ] + url
qrcode = NFCE [ uf . upper ( ) ] [ ' HTTPS ' ] + ' www. ' + NFCE [ uf . upper ( ) ] [ ' QR ' ] + url
url_chave = NFCE [ uf . upper ( ) ] [ ' HTTPS ' ] + ' www. ' + NFCE [ uf . upper ( ) ] [ ' URL ' ] + url
url_chave = NFCE [ uf . upper ( ) ] [ ' HTTPS ' ] + ' www. ' + NFCE [ uf . upper ( ) ] [ ' URL ' ]
else :
else :
qrcode = NFCE [ uf . upper ( ) ] [ ' HTTPS ' ] + ' www.homologacao. ' + NFCE [ uf . upper ( ) ] [ ' QR ' ] + url
qrcode = NFCE [ uf . upper ( ) ] [ ' HTTPS ' ] + ' www.homologacao. ' + NFCE [ uf . upper ( ) ] [ ' QR ' ] + url
url_chave = NFCE [ uf . upper ( ) ] [ ' HTTPS ' ] + ' www.homologacao. ' + NFCE [ uf . upper ( ) ] [ ' URL ' ] + url
url_chave = NFCE [ uf . upper ( ) ] [ ' HTTPS ' ] + ' www.homologacao. ' + NFCE [ uf . upper ( ) ] [ ' URL ' ]
# BA tem comportamento distindo para qrcode e url
# BA tem comportamento distindo para qrcode e url
elif uf . upper ( ) == ' BA ' :
elif uf . upper ( ) == ' BA ' :
if tpamb == ' 1 ' :
if tpamb == ' 1 ' :