forked from elmau/empresa-libre
Leyenda cancelada en PDF a partir de JSON
This commit is contained in:
parent
cf0c4b8622
commit
538a9f39ce
|
@ -29,6 +29,9 @@ from reportlab.platypus import Paragraph, Table, TableStyle, Spacer
|
|||
from reportlab.pdfgen import canvas
|
||||
|
||||
|
||||
CANCEL = False
|
||||
|
||||
|
||||
#~ https://github.com/kennethreitz/requests/blob/v1.2.3/requests/structures.py#L37
|
||||
class CaseInsensitiveDict(collections.MutableMapping):
|
||||
"""A case-insensitive ``dict``-like object.
|
||||
|
@ -358,6 +361,7 @@ class NumberedCanvas(canvas.Canvas):
|
|||
for state in self._saved_page_states:
|
||||
self.__dict__.update(state)
|
||||
self.draw_page_number(page_count)
|
||||
self.draw_cancel()
|
||||
canvas.Canvas.showPage(self)
|
||||
canvas.Canvas.save(self)
|
||||
return
|
||||
|
@ -375,6 +379,15 @@ class NumberedCanvas(canvas.Canvas):
|
|||
self.drawString(1.5 * cm, 1.5 * cm, text)
|
||||
return
|
||||
|
||||
def draw_cancel(self):
|
||||
global CANCEL
|
||||
if CANCEL:
|
||||
self.rotate(45)
|
||||
self.setFont('Helvetica', 100)
|
||||
self.setFillColor(colors.red)
|
||||
text = 'Cancelada'
|
||||
self.drawCentredString(20 * cm, 3 * cm, text)
|
||||
return
|
||||
|
||||
class TemplateInvoice(BaseDocTemplate):
|
||||
|
||||
|
@ -425,6 +438,7 @@ class TemplateInvoice(BaseDocTemplate):
|
|||
logo_style = styles.pop('logo', {})
|
||||
logo_path2 = data.pop('logo2', '')
|
||||
logo_style2 = styles.pop('logo2', {})
|
||||
sucursales = styles.pop('sucursales', {})
|
||||
|
||||
for k, v in styles.items():
|
||||
self._set_text(styles[k], data.get(k, ''))
|
||||
|
@ -443,6 +457,20 @@ class TemplateInvoice(BaseDocTemplate):
|
|||
rect[k] = rect[k] * cm
|
||||
self.canv.drawImage(logo_path2, **rect)
|
||||
|
||||
if sucursales:
|
||||
for k, sucursal in sucursales.items():
|
||||
values = sucursal.pop('textos')
|
||||
x = sucursal['rectangulo']['x']
|
||||
y = sucursal['rectangulo']['y']
|
||||
w = sucursal['rectangulo']['width']
|
||||
h = sucursal['rectangulo']['height']
|
||||
for v in values:
|
||||
self._set_text(sucursal, v)
|
||||
y -= h
|
||||
sucursal['rectangulo']['x'] = x
|
||||
sucursal['rectangulo']['y'] = y
|
||||
sucursal['rectangulo']['width'] = w
|
||||
sucursal['rectangulo']['height'] = h
|
||||
return
|
||||
|
||||
def _receptor(self, styles, data):
|
||||
|
@ -618,8 +646,10 @@ class TemplateInvoice(BaseDocTemplate):
|
|||
return self._data
|
||||
@data.setter
|
||||
def data(self, values):
|
||||
#~ print (values)
|
||||
global CANCEL
|
||||
# ~ print (values)
|
||||
self._data = values
|
||||
CANCEL = self._data['cancelada']
|
||||
|
||||
rows = self._conceptos(self._data['conceptos'])
|
||||
widths = [2 * cm, 9 * cm, 1.5 * cm, 2 * cm, 2 * cm, 3 * cm]
|
||||
|
@ -645,7 +675,7 @@ class TemplateInvoice(BaseDocTemplate):
|
|||
comprobante = self._comprobante2(
|
||||
self._custom_styles['comprobante'], self.data['comprobante'])
|
||||
|
||||
self._rows = [Spacer(0, 6*cm), table_conceptos, totales] + comprobante
|
||||
self._rows = [Spacer(0, 5.7 * cm), table_conceptos, totales] + comprobante
|
||||
|
||||
def render(self):
|
||||
frame = Frame(self.leftMargin, self.bottomMargin,
|
||||
|
|
Loading…
Reference in New Issue