Browse Source

[FIX]Campo CPF

pull/82/head
carcaroff 8 years ago
parent
commit
89a8d58060
  1. 39
      pytrustnfe/nfe/danfe.py
  2. 2
      setup.py

39
pytrustnfe/nfe/danfe.py

@ -3,8 +3,8 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Classe para geração de PDF da DANFE a partir de xml etree.fromstring
import os
from io import BytesIO
from cStringIO import StringIO as IO
from textwrap import wrap
from reportlab.lib import utils
@ -16,8 +16,6 @@ from reportlab.graphics.barcode import code128
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.enums import TA_CENTER
from reportlab.platypus import Paragraph, Image
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
def chunks(cString, nLen):
@ -57,6 +55,7 @@ def tagtext(oNode=None, cTag=None):
cText = ''
return cText
REGIME_TRIBUTACAO = {
'1': 'Simples Nacional',
'2': 'Simples Nacional, excesso sublimite de receita bruta',
@ -74,14 +73,6 @@ def get_image(path, width=1*cm):
class danfe(object):
def __init__(self, sizepage=A4, list_xml=None, recibo=True,
orientation='portrait', logo=None):
path = os.path.join(os.path.dirname(__file__), 'fonts')
pdfmetrics.registerFont(
TTFont('NimbusSanL-Regu',
os.path.join(path, 'NimbusSanL Regular.ttf')))
pdfmetrics.registerFont(
TTFont('NimbusSanL-Bold',
os.path.join(path, 'NimbusSanL Bold.ttf')))
self.width = 210 # 21 x 29,7cm
self.height = 297
self.nLeft = 10
@ -91,11 +82,11 @@ class danfe(object):
self.nlin = self.nTop
self.logo = logo
self.oFrete = {'0': '0 - Emitente',
'1': '1 - Dest/Remet',
'1': '1 - Destinatário',
'2': '2 - Terceiros',
'9': '9 - Sem Frete'}
self.oPDF_IO = BytesIO()
self.oPDF_IO = IO()
if orientation == 'landscape':
raise NameError('Rotina não implementada')
else:
@ -217,7 +208,7 @@ class danfe(object):
cNF = '{0:011,}'.format(int(cNF)).replace(",", ".")
self.stringcenter(self.nLeft+100, self.nlin+25, "%s" % (cNF))
self.stringcenter(self.nLeft+100, self.nlin+29, "SÉRIE %s" % (
self.stringcenter(self.nLeft+100, self.nlin+29, u"SÉRIE %s" % (
tagtext(oNode=elem_ide, cTag='serie')))
cPag = "Página %s de %s" % (str(self.Page), str(self.NrPages))
self.stringcenter(self.nLeft+100, self.nlin+32, cPag)
@ -293,7 +284,7 @@ class danfe(object):
oNode=elem_emit, cTag='CEP')
regime = tagtext(oNode=elem_emit, cTag='CRT')
cEnd += '<br />Regime Tributário: %s' % (REGIME_TRIBUTACAO[regime])
cEnd += u'<br />Regime Tributário: %s' % (REGIME_TRIBUTACAO[regime])
styleN.fontName = 'NimbusSanL-Regu'
styleN.fontSize = 7
@ -352,8 +343,10 @@ class danfe(object):
self.canvas.setFont('NimbusSanL-Regu', 8)
self.string(self.nLeft+1, self.nlin+7.5,
tagtext(oNode=elem_dest, cTag='xNome'))
self.string(nMr-69, self.nlin+7.5,
format_cnpj_cpf(tagtext(oNode=elem_dest, cTag='CNPJ')))
cnpj_cpf = format_cnpj_cpf(tagtext(oNode=elem_dest, cTag='CNPJ'))
if cnpj_cpf == '..-' or not cnpj_cpf:
cnpj_cpf = format_cnpj_cpf(tagtext(oNode=elem_dest, cTag='CPF'))
self.string(nMr-69, self.nlin+7.5, cnpj_cpf)
cDt, cHr = getdateUTC(tagtext(oNode=elem_ide, cTag='dhEmi'))
self.string(nMr-24, self.nlin+7.7, cDt + ' ' + cHr)
cDt, cHr = getdateUTC(tagtext(oNode=elem_ide, cTag='dhSaiEnt'))
@ -647,7 +640,7 @@ obsCont[@xCampo='NomeVendedor']")
self.canvas.setFont('NimbusSanL-Regu', 5)
nLin = self.nlin+10.5
for id in range(oPaginator[0], oPaginator[1]):
for id in xrange(oPaginator[0], oPaginator[1]):
item = el_det[id]
el_prod = item.find(".//{http://www.portalfiscal.inf.br/nfe}prod")
el_imp = item.find(
@ -657,9 +650,8 @@ obsCont[@xCampo='NomeVendedor']")
".//{http://www.portalfiscal.inf.br/nfe}ICMS")
el_imp_IPI = el_imp.find(
".//{http://www.portalfiscal.inf.br/nfe}IPI")
cCST = tagtext(oNode=el_imp_ICMS, cTag='orig') + \
tagtext(oNode=el_imp_ICMS, cTag='CST')
tagtext(oNode=el_imp_ICMS, cTag='CSOSN')
vBC = tagtext(oNode=el_imp_ICMS, cTag='vBC')
vICMS = tagtext(oNode=el_imp_ICMS, cTag='vICMS')
pICMS = tagtext(oNode=el_imp_ICMS, cTag='pICMS')
@ -729,7 +721,6 @@ obsCont[@xCampo='NomeVendedor']")
styleN.fontSize = 6
styleN.fontName = 'NimbusSanL-Regu'
styleN.leading = 7
fisco = tagtext(oNode=el_infAdic, cTag='infAdFisco')
observacoes = tagtext(oNode=el_infAdic, cTag='infCpl')
if fisco:
@ -768,7 +759,7 @@ obsCont[@xCampo='NomeVendedor']")
cNF = '{0:011,}'.format(int(cNF)).replace(",", ".")
self.string(self.width-self.nRight-nW+2, self.nlin+8, "%s" % (cNF))
self.string(self.width-self.nRight-nW+2, self.nlin+14,
"SÉRIE %s" % (tagtext(oNode=el_ide, cTag='serie')))
u"SÉRIE %s" % (tagtext(oNode=el_ide, cTag='serie')))
cDt, cHr = getdateUTC(tagtext(oNode=el_ide, cTag='dhEmi'))
cTotal = format_number(tagtext(oNode=el_total, cTag='vNF'),
@ -781,7 +772,7 @@ obsCont[@xCampo='NomeVendedor']")
oNode=el_dest, cTag='xMun') + ' - '
cEnd += tagtext(oNode=el_dest, cTag='UF')
cString = """
cString = u"""
RECEBEMOS DE %s OS PRODUTOS/SERVIÇOS CONSTANTES DA NOTA FISCAL INDICADA
ABAIXO. EMISSÃO: %s VALOR TOTAL: %s
DESTINATARIO: %s""" % (tagtext(oNode=el_emit, cTag='xNome'),

2
setup.py

@ -1,7 +1,7 @@
# coding=utf-8
from setuptools import setup, find_packages
VERSION = "0.9.3"
VERSION = "0.9.4"
setup(
name="PyTrustNFe3",

Loading…
Cancel
Save