Skip to content

Commit

Permalink
[FIX] Calcula previamente o tamanho do proximo item
Browse files Browse the repository at this point in the history
se ultrapassar o tamanho disponível finaliza e continua na próxima iteração
  • Loading branch information
danimaribeiro committed Oct 16, 2018
1 parent d4c3a8a commit f7ec2c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions pytrustnfe/nfe/danfe.py
Expand Up @@ -193,6 +193,7 @@ def __init__(self, sizepage=A4, list_xml=None, recibo=True,

self.impostos(oXML=oXML)
self.transportes(oXML=oXML)

index = self.produtos(
oXML=oXML, el_det=el_det, max_index=nId,
list_desc=list_desc, list_cod_prod=list_cod_prod)
Expand Down Expand Up @@ -667,6 +668,9 @@ def produtos(self, oXML=None, el_det=None, index=0, max_index=0,
nStep = 2.5 # Passo entre linhas
nH = 7.5 + (nHeight * nStep) # cabeçalho 7.5
self.nlin += 1
# nH é o altura da linha vertical, utilizar como referência
# somar a ele a altura atual que é nlin
maxHeight = self.nlin + nH

self.canvas.setFont('NimbusSanL-Bold', 7)
self.string(self.nLeft + 1, self.nlin + 1, 'DADOS DO PRODUTO/SERVIÇO')
Expand Down Expand Up @@ -712,11 +716,13 @@ def produtos(self, oXML=None, el_det=None, index=0, max_index=0,

# Conteúdo campos
self.canvas.setFont('NimbusSanL-Regu', 5)
nLin = self.nlin + 10.5
nLin = self.nlin + 10.0

for id in range(index, max_index + 1):

if nLin > 237:
line_height = max(len(list_cod_prod[id]), len(list_desc[id]))
line_height *= nStep
if nLin + line_height > maxHeight:
break

item = el_det[id]
Expand Down Expand Up @@ -832,10 +838,10 @@ def adicionais(self, oXML=None, tamanho_diminuir=0):
self.canvas.setFont('NimbusSanL-Regu', 5)
self.string(self.nLeft + 1, self.nlin + 4,
'INFORMAÇÕES COMPLEMENTARES')
self.string((self.width / 2) + 1, self.nlin + 4, 'RESERVADO AO FISCO')
self.string(((self.width / 3) * 2) + 1, self.nlin + 4, 'RESERVADO AO FISCO')
self.rect(self.nLeft, self.nlin + 2,
self.width - self.nLeft - self.nRight, 42 - tamanho_diminuir)
self.vline(self.width / 2, self.nlin + 2, 42 - tamanho_diminuir)
self.vline((self.width / 3) * 2, self.nlin + 2, 42 - tamanho_diminuir)
# Conteúdo campos
styles = getSampleStyleSheet()
styleN = styles['Normal']
Expand All @@ -847,7 +853,7 @@ def adicionais(self, oXML=None, tamanho_diminuir=0):
if fisco:
observacoes = fisco + ' ' + observacoes
P = Paragraph(observacoes, styles['Normal'])
w, h = P.wrap(92 * mm, 32 * mm)
w, h = P.wrap(128 * mm, 32 * mm)
altura = (self.height - self.nlin - 5) * mm
P.drawOn(self.canvas, (self.nLeft + 1) * mm, altura - h)
self.nlin += 36
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup, find_packages


VERSION = "1.0.17"
VERSION = "1.0.18"


setup(
Expand Down

0 comments on commit f7ec2c5

Please sign in to comment.