Skip to content

Commit

Permalink
Removido dateutil para timezone da versão nova (3.6) do python Close #15
Browse files Browse the repository at this point in the history
  • Loading branch information
juniortada committed May 21, 2018
1 parent 141bddc commit 8f6351a
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions pynfe/processamento/serializacao.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-

import time
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, \
Expand All @@ -9,6 +7,7 @@
from pynfe.utils.webservices import NFCE
import base64
import hashlib
from datetime import datetime


class Serializacao(object):
Expand Down Expand Up @@ -308,6 +307,9 @@ def _serializar_produto_servico(self, produto_servico, modelo, tag_raiz='det', r
etree.SubElement(icms_item, 'vBC').text = '{:.2f}'.format(produto_servico.icms_valor_base_calculo or 0) # Valor da BC do ICMS
etree.SubElement(icms_item, 'pICMS').text = str(produto_servico.icms_aliquota) # Alíquota do imposto
etree.SubElement(icms_item, 'vICMS').text = '{:.2f}'.format(produto_servico.icms_valor or 0) # Valor do ICMS
etree.SubElement(icms_item, 'vBCFCP').text = '{:.2f}'.format(produto_servico.fcp_base_calculo) # Base de calculo FCP
etree.SubElement(icms_item, 'pFCP').text = '{:.2f}'.format(produto_servico.fcp_percentual) # Percentual FCP
etree.SubElement(icms_item, 'vFCP').text = '{:.2f}'.format(produto_servico.fcp_valor) # Valor Fundo Combate a Pobreza
# Impostos não implementados
else:
raise NotImplementedError
Expand Down Expand Up @@ -398,35 +400,24 @@ def _serializar_produto_servico(self, produto_servico, modelo, tag_raiz='det', r
return raiz

def _serializar_nota_fiscal(self, nota_fiscal, tag_raiz='infNFe', retorna_string=True):
#raiz = etree.Element('NFe', xmlns='http://www.portalfiscal.inf.br/nfe')
raiz = etree.Element(tag_raiz, versao=self._versao)

# 'Id' da tag raiz
# Ex.: NFe35080599999090910270550010000000011518005123
raiz.attrib['Id'] = nota_fiscal.identificador_unico

# timezone Brasília -03:00
# bug no python < 3.5 no windows
# http://bugs.python.org/issue20010
# TODO utilizar assim quando python superior a 3.5
# tz = time.strftime("%z")
from datetime import datetime
from dateutil import tz
tz = datetime.now(tz.tzlocal()).strftime('%z')
tz = datetime.now().astimezone().strftime('%z')
tz = "{}:{}".format(tz[:-2], tz[-2:])

# Dados da Nota Fiscal
ide = etree.SubElement(raiz, 'ide')
etree.SubElement(ide, 'cUF').text = CODIGOS_ESTADOS[nota_fiscal.uf]
etree.SubElement(ide, 'cNF').text = nota_fiscal.codigo_numerico_aleatorio
etree.SubElement(ide, 'natOp').text = nota_fiscal.natureza_operacao
# Removido na NF-e 4.00
# etree.SubElement(ide, 'indPag').text = str(nota_fiscal.forma_pagamento)
etree.SubElement(ide, 'mod').text = str(nota_fiscal.modelo)
etree.SubElement(ide, 'serie').text = nota_fiscal.serie
etree.SubElement(ide, 'nNF').text = str(nota_fiscal.numero_nf)
etree.SubElement(ide, 'dhEmi').text = nota_fiscal.data_emissao.strftime('%Y-%m-%dT%H:%M:%S') + tz
#etree.SubElement(ide, 'dhSaiEnt').text = nota_fiscal.data_saida_entrada.strftime('%Y-%m-%dT%H:%M:%S') + tz
"""dhCont Data e Hora da entrada em contingência E B01 D 0-1 Formato AAAA-MM-DDThh:mm:ssTZD (UTC - Universal
Coordinated Time)
Exemplo: no formato UTC para os campos de Data-Hora, "TZD" pode ser -02:00 (Fernando de Noronha), -03:00 (Brasília) ou -04:00 (Manaus), no
Expand Down Expand Up @@ -635,9 +626,7 @@ def _serializar_nota_fiscal(self, nota_fiscal, tag_raiz='infNFe', retorna_string
return raiz

def serializar_evento(self, evento, tag_raiz='evento', retorna_string=False):

# timezone Brasília -03:00
tz = time.strftime("%z")
tz = datetime.now().astimezone().strftime('%z')
tz = "{}:{}".format(tz[:-2], tz[-2:])
raiz = etree.Element(tag_raiz, versao='1.00', xmlns=NAMESPACE_NFE)
e = etree.SubElement(raiz, 'infEvento', Id=evento.identificador)
Expand Down

0 comments on commit 8f6351a

Please sign in to comment.