9f29c6c1e44ace32f62d1a1b7631603b33dcae50
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

1) # -*- coding: utf-8 -*-
2) # (C) 2011 by Bernd Wurst <bernd@schokokeks.org>
3) 
4) # This file is part of Bib2011.
5) #
6) # Bib2011 is free software: you can redistribute it and/or modify
7) # it under the terms of the GNU General Public License as published by
8) # the Free Software Foundation, either version 3 of the License, or
9) # (at your option) any later version.
10) #
11) # Bib2011 is distributed in the hope that it will be useful,
12) # but WITHOUT ANY WARRANTY; without even the implied warranty of
13) # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14) # GNU General Public License for more details.
15) #
16) # You should have received a copy of the GNU General Public License
17) # along with Bib2011.  If not, see <http://www.gnu.org/licenses/>.
18) 
19) import os.path
20) import re
21) 
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

22) from reportlab.lib.pagesizes import A4
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

23) # reportlab imports
24) from reportlab.lib.units import cm, inch
25) from reportlab.pdfbase import pdfmetrics
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

26) from reportlab.pdfbase.ttfonts import TTFont, TTFError
27) from reportlab.pdfgen import canvas
28) 
29) from .InvoiceObjects import InvoiceTable, InvoiceText, InvoiceImage, GUTSCHRIFT
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

30) 
31) 
32) def _formatPrice(price, symbol='€'):
33)     '''_formatPrice(price, symbol='€'):
34)     Gets a floating point value and returns a formatted price, suffixed by 'symbol'. '''
35)     s = ("%.2f" % price).replace('.', ',')
36)     pat = re.compile(r'([0-9])([0-9]{3}[.,])')
37)     while pat.search(s):
38)         s = pat.sub(r'\1.\2', s)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

39)     return s + ' ' + symbol
40) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

41) 
42) def find_font_file(filename):
43)     for n in range(4):
44)         candidate = os.path.abspath(os.path.join(os.path.dirname(__file__), '../' * n, 'ressource/fonts', filename))
45)         if os.path.exists(candidate):
46)             return candidate
47) 
48) 
49) def _registerFonts():
50)     fonts = [
51)         ("DejaVu", "DejaVuSans.ttf"),
52)         ("DejaVu-Bold", "DejaVuSans-Bold.ttf"),
53)         ("DejaVu-Italic", "DejaVuSans-Oblique.ttf"),
54)         ("DejaVu-BoldItalic", "DejaVuSans-BoldOblique.ttf")
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

55)     ]
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

56)     for fontname, fontfile in fonts:
57)         found = False
58)         try:
59)             pdfmetrics.registerFont(TTFont(fontname, fontfile))
60)             found = True
61)         except TTFError:
62)             pass
63)         if not found:
64)             f = find_font_file(fontfile)
65)             if f:
66)                 pdfmetrics.registerFont(TTFont(fontname, f))
67) 
68) 
69) class PDF(object):
70)     # Set default font size
71)     default_font_size = 8
72)     font = 'DejaVu'
73)     # set margins
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

74)     topmargin = 2 * cm
75)     bottommargin = 2.2 * cm
76)     leftmargin = 2 * cm
77)     rightmargin = 2 * cm
78)     rightcolumn = 13 * cm
79) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

80)     canvas = None
81)     num_pages = 1
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

82)     font_height = 0.3 * cm
83)     line_padding = 0.1 * cm
84)     line_height = font_height + 0.1 * cm
85) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

86)     invoice = None
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

87) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

88)     def __init__(self, invoice):
89)         _registerFonts()
90)         from io import BytesIO
91)         self.fd = BytesIO()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

92)         self.canvas = canvas.Canvas(self.fd, pagesize=A4)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

93) 
94)         self.invoice = invoice
95) 
96)         self.topcontent = -self.topmargin
97)         self.leftcontent = self.leftmargin
98)         self.rightcontent = A4[0] - self.rightmargin
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

99)         self.bottomcontent = -(A4[1] - self.bottommargin)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

100) 
101)         self.font_size = 8
102)         self.x = 2.0 * cm
103)         self.y = -4.8 * cm - self.font_size - 1
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

104) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

105)         self.canvas.setFont(self.font, self.font_size)
106) 
107)     def _splitToWidth(self, text, width, font, size):
108)         '''_splitToWidth(canvas, text, width, font, size)
109)         Split a string to several lines of a given width.'''
110)         lines = []
111)         paras = text.split('\n')
112)         for para in paras:
113)             words = para.split(' ')
114)             while len(words) > 0:
115)                 mywords = [words[0], ]
116)                 del words[0]
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

117)                 while len(words) > 0 and self.canvas.stringWidth(' '.join(mywords) + ' ' + words[0], font,
118)                                                                  size) <= width:
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

119)                     mywords.append(words[0])
120)                     del words[0]
121)                 lines.append(' '.join(mywords))
122)         return lines
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

123) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

124)     def _PageMarkers(self):
125)         """Setzt Falzmarken"""
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

126)         self.canvas.setStrokeColor((0, 0, 0))
127)         self.canvas.setLineWidth(0.01 * cm)
128)         self.canvas.lines([(0.3 * cm, -10.5 * cm, 0.65 * cm, -10.5 * cm),
129)                            (0.3 * cm, -21.0 * cm, 0.65 * cm, -21.0 * cm),
130)                            (0.3 * cm, -14.85 * cm, 0.7 * cm, -14.85 * cm)])
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

131) 
132)     def _lineHeight(self, fontsize=None, font=None):
133)         if not fontsize:
134)             fontsize = self.default_font_size
135)         if not font:
136)             font = self.font
137)         face = pdfmetrics.getFont(font).face
138)         string_height = (face.ascent - face.descent) / 1000 * fontsize
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

139)         return string_height + 0.1 * cm
140) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

141)     def _partHeight(self, part):
142)         height = 0
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

143)         if isinstance(part, InvoiceText):
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

144)             left, right = self.leftcontent, self.rightcontent
145)             if part.urgent:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

146)                 left += 1.5 * cm
147)                 right -= 1.5 * cm
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

148)                 height += len(part.paragraphs) * 3 * self.line_padding
149)                 # Rechne eine Zeile mehr für den Rahmen
150)                 height += self.line_height
151)             if part.headline:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

152)                 height += (len(self._splitToWidth(part.headline, right - left, self.font + '-Bold',
153)                                                   self.default_font_size + 1)) * self.line_height) + self.line_padding
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

154)             for para in part.paragraphs:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

155)                 height += (len(self._splitToWidth(para, right - left, self.font,
156)                                                   self.default_font_size)) * self.line_height) + self.line_padding
157)         elif isinstance(part, InvoiceTable):
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

158)             # Eine Zeile plus 2 mal line_padding für Tabellenkopf
159)             height = self.line_height + 2 * self.line_padding
160)             # Wenn nur ein Element (plus Summen) hin passt, reicht uns das
161)             el = part.entries[0]
162)             # Die Abstände oben und unten
163)             height += 2 * self.line_padding
164)             # Die Breite ist konservativ
165)             if el['type'] == 'title':
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

166)                 height += self.line_height + 0.2 * cm
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

167)             else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

168)                 height += self.line_height * len(self._splitToWidth(el['subject'], 9.3 * cm, self.font, self.font_size))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

169)             if 'desc' in el and el['desc'] != '':
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

170)                 height += self.line_height * len(self._splitToWidth(el['desc'], 11 * cm, self.font, self.font_size))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

171)             if part.vatType == 'net':
172)                 # Eine Zeile mehr
173)                 height += self.line_height + self.line_padding
174)             # Für die MwSt-Summen
175)             height += (self.line_height + self.line_padding) * len(part.vat)
176)             # Für den Rechnungsbetrag
177)             height += self.line_height + self.line_padding
178)         return height
179) 
180)     def _tableHead(self, part):
181)         self.canvas.setFont(self.font, self.font_size)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

182)         self.canvas.drawString(self.leftcontent + (0.1 * cm), self.y - self.line_height + self.line_padding, 'Anz.')
183)         self.canvas.drawString(self.leftcontent + (2.1 * cm), self.y - self.line_height + self.line_padding,
184)                                'Beschreibung')
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

185)         if len(part.vat) == 1:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

186)             self.canvas.drawRightString(self.leftcontent + (14.3 * cm), self.y - self.line_height + self.line_padding,
187)                                         'Einzelpreis')
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

188)         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

189)             self.canvas.drawRightString(self.leftcontent + (13.3 * cm), self.y - self.line_height + self.line_padding,
190)                                         'Einzelpreis')
191)         self.canvas.drawRightString(self.leftcontent + (16.8 * cm), self.y - self.line_height + self.line_padding,
192)                                     'Gesamtpreis')
193)         self.canvas.setLineWidth(0.01 * cm)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

194)         self.canvas.line(self.leftcontent, self.y - self.line_height, self.rightcontent, self.y - self.line_height)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

195)         self.y -= self.line_height + 0.02 * cm
196) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

197)     def _PageWrap(self):
198)         '''Seitenumbruch'''
199)         self.num_pages += 1
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

200)         self.canvas.setFont(self.font, self.default_font_size - 2)
201)         self.canvas.drawRightString(self.rightcontent, self.bottomcontent + self.line_padding,
202)                                     'Fortsetzung auf Seite %i' % self.num_pages)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

203)         self.canvas.showPage()
204)         self.basicPage()
205)         self.y = self.topcontent - self.font_size
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

206)         self.canvas.setFillColor((0, 0, 0))
207)         self.canvas.setFont(self.font, self.font_size - 2)
208)         self.canvas.drawCentredString(self.leftcontent + (self.rightcontent - self.leftcontent) / 2, self.y,
209)                                       '- Seite %i -' % self.num_pages)
210) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

211)     def _Footer(self):
212)         self.canvas.setStrokeColor((0, 0, 0))
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

213)         self.canvas.setFillColor((0, 0, 0))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

214)         self.canvas.line(self.leftcontent, self.bottomcontent, self.rightcontent, self.bottomcontent)
215)         self.canvas.setFont(self.font, 7)
216)         lines = list(filter(None, [
217)             self.invoice.seller['trade_name'],
218)             self.invoice.seller['name'] if self.invoice.seller['trade_name'] else None,
219)             self.invoice.seller['website'],
220)             self.invoice.seller['email'],
221)         ]))
222)         c = 0
223)         for line in lines:
224)             c += 10
225)             self.canvas.drawString(self.leftcontent, self.bottomcontent - c, line)
226) 
227)         if self.invoice.seller_vat_id:
228)             lines = list(filter(None, [
229)                 "USt-ID: " + self.invoice.seller_vat_id
230)             ]))
231)             c = 0
232)             for line in lines:
233)                 c += 10
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

234)                 self.canvas.drawString(self.leftcontent + ((self.rightcontent - self.leftcontent) // 3),
235)                                        self.bottomcontent - c, line)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

236) 
237)         if not self.invoice.debit:
238)             iban = self.invoice.seller_bank_data['iban']
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

239)             iban = ' '.join([iban[i:i + 4] for i in range(0, len(iban), 4)])
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

240)             lines = [
241)                 f"IBAN: {iban}",
242)                 self.invoice.seller_bank_data['bankname'],
Bernd Wurst Kleine Korrekturen, mache B...

Bernd Wurst authored 9 months ago

243)                 f"BIC: {self.invoice.seller_bank_data['bic']}" if self.invoice.seller_bank_data['bic'] else None,
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

244)             ]
245)             c = 0
246)             for line in lines:
247)                 c += 10
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

248)                 self.canvas.drawString(self.leftcontent + ((self.rightcontent - self.leftcontent) // 3) * 2,
249)                                        self.bottomcontent - c, line)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

250) 
251)     def basicPage(self):
252)         # Set marker to top.
253)         self.canvas.translate(0, A4[1])
254) 
255)         self._PageMarkers()
256)         self._Footer()
257) 
258)     def addressBox(self):
259)         lines = [
260)             self.invoice.seller['trade_name'],
261)             self.invoice.seller['address']['line1'],
262)             self.invoice.seller['address']['line2'],
263)             self.invoice.seller['address']['line3'],
264)             self.invoice.seller['address']['postcode'] + ' ' + self.invoice.seller['address']['city_name'],
265)         ]
266)         address = ' · '.join(filter(None, lines))
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

267)         self.canvas.drawString(self.x, self.y + 0.1 * cm, f' {address}')
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

268)         self.canvas.line(self.x, self.y, self.x + (8.5 * cm), self.y)
269)         self.y = self.y - self.font_size - 3
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

270) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

271)         font_size = 11
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

272)         x = self.x + 0.5 * cm
273)         self.y -= 0.5 * cm
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

274)         self.canvas.setFont(self.font, font_size)
275)         addresslines = filter(None, [
276)             self.invoice.customer['name'].strip(),
277)             self.invoice.customer['address']['line1'] or '',
278)             self.invoice.customer['address']['line2'] or '',
279)             self.invoice.customer['address']['line3'] or '',
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

280)             ((self.invoice.customer['address']['postcode'] or '') + ' ' + (
281)                     self.invoice.customer['address']['city_name'] or '')).strip(),
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

282)         ])
283)         for line in addresslines:
284)             self.canvas.drawString(x, self.y, line)
285)             self.y -= font_size * 0.03527 * cm * 1.2
286) 
287)     def firstPage(self):
288)         self.basicPage()
289)         self.addressBox()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

290) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

291)         self.y = self.topcontent
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

292)         self.canvas.drawImage(self.invoice.logo_image_file, self.rightcolumn, self.topcontent - (2 * cm),
293)                               height=2 * cm, preserveAspectRatio=True, anchor='nw')
294)         self.y -= (2.5 * cm)
295)         self.canvas.setFont(self.font + "-Bold", self.font_size)
296)         self.canvas.drawString(self.rightcolumn, self.y,
297)                                self.invoice.seller['trade_name'] or self.invoice.seller['name'])
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

298)         self.y -= (self.font_size + 5)
299)         self.canvas.setFont(self.font, self.font_size)
300)         lines = [
301)             self.invoice.seller['name'] if self.invoice.seller['trade_name'] else None,
302)             self.invoice.seller['address']['line1'],
303)             self.invoice.seller['address']['line2'],
304)             self.invoice.seller['address']['line3'],
305)             self.invoice.seller['address']['postcode'] + ' ' + self.invoice.seller['address']['city_name'],
306)             self.invoice.seller['website'],
307)         ]
308)         address = filter(None, lines)
309)         for line in address:
310)             self.canvas.drawString(self.rightcolumn, self.y, line)
311)             self.y -= (self.font_size + 5)
312)         self.y -= 5
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

313)         if self.invoice.seller['phone']:
314)             self.canvas.drawString(self.rightcolumn, self.y, f"Tel: {self.invoice.seller['phone']}")
315)             self.y -= (self.font_size + 5)
316)         if self.invoice.seller['email']:
317)             self.canvas.drawString(self.rightcolumn, self.y, f"E-Mail: {self.invoice.seller['email']}")
318)             self.y -= (self.font_size + 10)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

319)         self.y = -9.5 * cm
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

320) 
321)     def title(self, title):
322)         self.canvas.setTitle(title)
323)         self.canvas.drawString(self.leftcontent, self.y, title)
324) 
325)     def renderRechnung(self):
326)         self.firstPage()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

327)         self.canvas.setFont(self.font + '-Bold', self.font_size + 3)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

328)         self.title(self.invoice.title)
329) 
330)         if self.invoice.tender:
331)             self.canvas.setFont(self.font, self.font_size)
332)             self.canvas.drawString(self.rightcolumn, self.y, "Erstellungsdatum:")
333)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.date.strftime('%d. %m. %Y'))
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

334)             self.y -= (self.font_size + 0.1 * cm)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

335)         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

336)             self.canvas.setFont(self.font + '-Bold', self.font_size)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

337)             self.canvas.drawString(self.rightcolumn, self.y, "Bei Fragen bitte immer angeben:")
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

338)             self.y -= (self.font_size + 0.2 * cm)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

339)             self.canvas.setFont(self.font, self.font_size)
340)             self.canvas.drawString(self.rightcolumn, self.y, "Rechnungsdatum:")
341)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.date.strftime('%d. %m. %Y'))
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

342)             self.y -= (self.font_size + 0.1 * cm)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

343)             self.canvas.drawString(self.rightcolumn, self.y, "Rechnungsnummer:")
344)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.id)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

345)             self.y -= (self.font_size + 0.1 * cm)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

346)         if self.invoice.customerno:
347)             self.canvas.drawString(self.rightcolumn, self.y, "Kundennummer:")
348)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.customerno)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

349)             self.y -= (self.font_size + 0.5 * cm)
Bernd Wurst Referenznummern auf allen A...

Bernd Wurst authored 9 months ago

350)         if self.invoice.leitweg_id:
351)             self.canvas.drawString(self.rightcolumn, self.y, "Leitweg-ID:")
352)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.leitweg_id)
353)             self.y -= (self.font_size + 0.1 * cm)
354)         if self.invoice.buyer_reference:
355)             self.canvas.drawString(self.rightcolumn, self.y, "Kunden-Referenz:")
356)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.buyer_reference)
357)             self.y -= (self.font_size + 0.1 * cm)
358)         if self.invoice.contract_number:
359)             self.canvas.drawString(self.rightcolumn, self.y, "Vertragsnummer:")
360)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.contract_number)
361)             self.y -= (self.font_size + 0.1 * cm)
362)         if self.invoice.order_number:
363)             self.canvas.drawString(self.rightcolumn, self.y, "Ihre Bestellnummer:")
364)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.order_number)
365)             self.y -= (self.font_size + 0.1 * cm)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

366)         self.canvas.setFont(self.font, self.font_size)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

367) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

368)         if self.invoice.salutation:
369)             self.canvas.drawString(self.leftcontent, self.y, self.invoice.salutation)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

370)             self.y -= self.font_size + 0.2 * cm
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

371)             introText = 'hiermit stellen wir Ihnen die nachfolgend genannten Leistungen in Rechnung.'
372)             if self.invoice.tender:
373)                 introText = 'hiermit unterbreiten wir Ihnen folgendes Angebot.'
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

374)             if self.invoice.type == GUTSCHRIFT:
375)                 introText = 'nach unserer Berechnung entsteht für Sie folgende Gutschrift.'
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

376)             intro = self._splitToWidth(introText, self.rightcontent - self.leftcontent, self.font, self.font_size)
377)             for line in intro:
378)                 self.canvas.drawString(self.leftcontent, self.y, line)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

379)                 self.y -= self.font_size + 0.1 * cm
380)             self.y -= self.font_size + 0.1 * cm
381) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

382)         font_size = self.default_font_size
383)         for part in self.invoice.parts:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

384)             if self.y - self._partHeight(part) < (self.bottomcontent + (0.5 * cm)):
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

385)                 self._PageWrap()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

386)                 self.y = self.topcontent - self.font_size - self.line_padding * 3
387)             if isinstance(part, InvoiceTable):
388) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

389)                 left = self.leftcontent
390)                 right = self.rightcontent
391)                 self._tableHead(part)
392)                 temp_sum = 0.0
393)                 odd = True
394)                 for el in part.entries:
395)                     if el['type'] == 'title':
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

396)                         self.y -= self.line_padding + 0.2 * cm
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

397)                         self.canvas.setFillColorRGB(0, 0, 0)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

398)                         self.canvas.setFont(self.font + '-Italic', font_size)
399)                         self.canvas.drawString(left, self.y - self.font_height, el['title'])
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

400)                         self.canvas.setFont(self.font, font_size)
401)                         self.y -= self.line_height + self.line_padding
402)                     else:
403)                         if len(part.vat) == 1:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

404)                             subject = self._splitToWidth(el['subject'], 9.8 * cm, self.font, font_size)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

405)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

406)                             subject = self._splitToWidth(el['subject'], 8.8 * cm, self.font, font_size)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

407)                         desc = []
408)                         if 'desc' in el and el['desc'] != '':
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

409)                             desc = self._splitToWidth(el['desc'], 14.0 * cm, self.font, font_size)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

410)                         if 'period_start' in el and el['period_start']:
411)                             if 'period_end' in el and el['period_end']:
412)                                 desc.extend(self._splitToWidth('Leistungszeitraum: %s - %s' %
413)                                                                (el['period_start'].strftime('%d.%m.%Y'),
414)                                                                 el['period_end'].strftime('%d.%m.%Y')),
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

415)                                                                14.0 * cm, self.font, font_size))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

416)                             else:
417)                                 desc.extend(self._splitToWidth('Leistungsdatum: %s' %
418)                                                                (el['period_start'].strftime('%d.%m.%Y'),),
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

419)                                                                14.0 * cm, self.font, font_size))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

420)                         need_lines = len(subject) + len(desc)
421)                         # need page wrap?
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

422)                         if self.y - (need_lines + 1 * (self.line_height + self.line_padding)) < (
423)                                 self.bottomcontent + 1 * cm):
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

424)                             self.canvas.setFont(self.font + '-Italic', font_size)
425)                             # Zwischensumme
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

426)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Zwischensumme:')
427)                             self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height,
428)                                                         _formatPrice(temp_sum))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

429)                             # page wrap
430)                             self._PageWrap()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

431)                             self.y = self.topcontent - font_size - self.line_padding * 3
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

432)                             # header
433)                             self._tableHead(part)
434)                             self.y -= self.line_padding * 3
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

435)                             odd = True
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

436)                             # übertrag
437)                             self.canvas.setFont(self.font + '-Italic', font_size)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

438)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Übertrag:')
439)                             self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height,
440)                                                         _formatPrice(temp_sum))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

441)                             self.y -= self.font_height + self.line_padding * 3
442)                             self.canvas.setFont(self.font, self.default_font_size)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

443) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

444)                         # Zwischensumme (inkl. aktueller Posten)
445)                         temp_sum += el['total']
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

446) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

447)                         # draw the background
448)                         if not odd:
449)                             self.canvas.setFillColorRGB(0.9, 0.9, 0.9)
450)                         else:
451)                             self.canvas.setFillColorRGB(1, 1, 1)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

452)                         self.canvas.rect(left, self.y - (need_lines * self.line_height) - (2 * self.line_padding),
453)                                          height=(need_lines * self.line_height) + (2 * self.line_padding),
454)                                          width=right - left, fill=1, stroke=0)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

455)                         self.canvas.setFillColorRGB(0, 0, 0)
456)                         self.y -= self.line_padding
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

457)                         self.canvas.drawRightString(left + 1.1 * cm, self.y - self.font_height, '%.0f' % el['count'])
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

458)                         if el['unit']:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

459)                             self.canvas.drawString(left + 1.2 * cm, self.y - self.font_height, el['unit'])
460)                         self.canvas.drawString(left + 2.2 * cm, self.y - self.font_height, subject[0])
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

461)                         if len(part.vat) == 1:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

462)                             self.canvas.drawRightString(left + 14.3 * cm, self.y - self.font_height,
463)                                                         _formatPrice(el['price']))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

464)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

465)                             self.canvas.drawRightString(left + 13.3 * cm, self.y - self.font_height,
466)                                                         _formatPrice(el['price']))
467)                             self.canvas.drawString(left + 13.7 * cm, self.y - self.font_height,
468)                                                    str(part.vat[el['vat']][1]))
469)                         if el['tender']:
470)                             self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, 'eventual')
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

471)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

472)                             self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height,
473)                                                         _formatPrice(el['total']))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

474)                         subject = subject[1:]
475)                         x = 1
476)                         for line in subject:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

477)                             self.canvas.drawString(left + 2.2 * cm, self.y - (x * self.line_height) - self.font_height,
478)                                                    line)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

479)                             x += 1
480)                         for line in desc:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

481)                             self.canvas.drawString(left + 2.2 * cm, self.y - (x * self.line_height) - self.font_height,
482)                                                    line)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

483)                             x += 1
484)                         odd = not odd
485)                         self.y -= (need_lines * self.line_height) + self.line_padding
486)                 if part.summary:
487)                     need_lines = 5
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

488)                     if self.y - (need_lines + 1 * (self.line_height + self.line_padding)) < (
489)                             self.bottomcontent + 1 * cm):
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

490)                         self.canvas.setFont(self.font + '-Italic', font_size)
491)                         # Zwischensumme
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

492)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Zwischensumme:')
493)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, _formatPrice(temp_sum))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

494)                         # page wrap
495)                         self._PageWrap()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

496)                         self.y = self.topcontent - font_size - self.line_padding * 3
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

497)                         # header
498)                         self._tableHead(part)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

499)                         odd = True
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

500)                         # übertrag
501)                         self.canvas.setFont(self.font + '-Italic', font_size)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

502)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Übertrag:')
503)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, _formatPrice(temp_sum))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

504)                         self.y -= self.font_height + self.line_padding
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

505)                     self.y -= (0.3 * cm)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

506)                     if part.vatType == 'gross':
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

507)                         self.canvas.setFont(self.font + '-Bold', font_size)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

508)                         if self.invoice.tender or not self.invoice.official:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

509)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Gesamtbetrag:')
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

510)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

511)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Rechnungsbetrag:')
512)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, _formatPrice(part.sum))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

513)                         if self.invoice.official:
514)                             self.canvas.setFont(self.font, font_size)
515)                             self.y -= self.line_height + self.line_padding
516)                             summaries = []
517)                             vat = 0.0
518)                             if len(part.vat) == 1 and list(part.vat.keys())[0] == 0.0:
519)                                 self.canvas.drawString(left, self.y - self.font_height,
520)                                                        'Dieser Beleg wurde ohne Ausweis von MwSt erstellt.')
521)                                 self.y -= self.line_height
522)                             else:
523)                                 if len(part.vat) == 1:
524)                                     vat = list(part.vat.keys())[0]
525)                                     if self.invoice.tender:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

526)                                         summaries.append(('Im Gesamtbetrag sind %.1f%% MwSt enthalten:' % (vat * 100),
527)                                                           _formatPrice((part.sum / (vat + 1)) * vat)))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

528)                                     else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

529)                                         summaries.append((
530)                                             'Im Rechnungsbetrag sind %.1f%% MwSt enthalten:' % (vat * 100),
531)                                             _formatPrice((part.sum / (vat + 1)) * vat)))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

532)                                 else:
533)                                     for vat, vatdata in part.vat.items():
534)                                         if vat > 0:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

535)                                             summaries.append(('%s: Im Teilbetrag von %s sind %.1f%% MwSt enthalten:' % (
536)                                                 vatdata[1], _formatPrice(vatdata[0]), vat * 100),
537)                                                               _formatPrice((vatdata[0] / (vat + 1)) * vat)))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

538)                                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

539)                                             summaries.append(('%s: Durchlaufende Posten ohne Berechnung von MwSt.' % (
540)                                                 vatdata[1]), 0.0))
541)                             summaries.append(('Nettobetrag:', _formatPrice(part.sum - (part.sum / (vat + 1)) * vat)))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

542)                             summaries.sort()
543)                             for line in summaries:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

544)                                 self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, line[0])
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

545)                                 if line[1]:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

546)                                     self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, line[1])
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

547)                                 self.y -= self.line_height
548)                     elif len(part.vat) == 1 and part.vatType == 'net':
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

549)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Nettobetrag:')
550)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, _formatPrice(part.sum))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

551)                         self.y -= self.line_height
552)                         summaries = []
553)                         if list(part.vat.keys())[0] == 0.0:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

554)                             self.canvas.drawString(left, self.y - self.font_height,
555)                                                    'Dieser Beleg wurde ohne Ausweis von MwSt erstellt.')
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

556)                             self.y -= self.line_height
557)                         else:
558)                             if len(part.vat) == 1:
559)                                 vat = list(part.vat.keys())[0]
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

560)                                 summaries.append(('zzgl. %.1f%% MwSt:' % (vat * 100), _formatPrice(vat * part.sum)))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

561)                             else:
562)                                 for vat, vatdata in part.vat.items():
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

563)                                     summaries.append(('zzgl. %.1f%% MwSt (%s):' % (vat * 100, vatdata[1]),
564)                                                       _formatPrice(vat * vatdata[0])))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

565)                         summaries.sort()
566)                         for line in summaries:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

567)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, line[0])
568)                             self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, line[1])
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

569)                             self.y -= self.line_height
570)                         sum = 0
571)                         for vat, vatdata in part.vat.items():
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

572)                             sum += (vat + 1) * vatdata[0]
573)                         self.canvas.setFont(self.font + '-Bold', font_size)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

574)                         if self.invoice.tender:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

575)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Gesamtbetrag:')
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

576)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

577)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Rechnungsbetrag:')
578)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, _formatPrice(sum))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

579)                         self.canvas.setFont(self.font, font_size)
580)                         self.y -= self.line_height + self.line_padding
581)                     paysum = 0.0
582)                     for pay in part.payments:
583)                         paysum += pay['amount']
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

584)                         descr = 'Zahlung'
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

585)                         if pay['type'] == 'cash':
586)                             descr = 'gegeben'
587)                         elif pay['type'] == 'return':
588)                             descr = 'zurück'
589)                         elif pay['type'] == 'ec':
590)                             descr = 'Kartenzahlung (EC)'
591)                         elif pay['type'] == 'gutschein':
592)                             descr = 'Einlösung Gutschein'
593)                         if pay['date'] != self.invoice.date:
594)                             descr += ' am %s' % (pay['date'].strftime('%d. %m. %Y'))
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

595)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, descr + ':')
596)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height,
597)                                                     _formatPrice(pay['amount']))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

598)                         self.y -= self.line_height
599)                     sum = part.sum
600)                     if part.vatType == 'net':
601)                         sum = 0
602)                         for vat, vatdata in part.vat.items():
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

603)                             sum += (vat + 1) * vatdata[0]
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

604)                     rest = sum - paysum
605)                     if part.payments and rest > 0:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

606)                         self.canvas.setFont(self.font + '-Bold', font_size)
607)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height,
608)                                                     'Offener Rechnungsbetrag:')
609)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, _formatPrice(rest))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

610)                         self.canvas.setFont(self.font, font_size)
611)                         self.y -= self.line_height + self.line_padding
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

612) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

613)                     self.y -= self.line_padding
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

614)             elif isinstance(part, InvoiceText):
615)                 my_font_size = font_size + part.fontsize  # Relative Schriftgröße beachten
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

616)                 self.canvas.setFont(self.font, my_font_size)
617)                 left, right = self.leftcontent, self.rightcontent
618)                 firsttime = True
619)                 headlines = []
620)                 if part.urgent:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

621)                     left += 1.5 * cm
622)                     right -= 1.5 * cm
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

623)                 if part.headline:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

624)                     headlines = self._splitToWidth(part.headline, right - left, self.font, my_font_size)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

625)                 for para in part.paragraphs:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

626)                     lines = self._splitToWidth(para, right - left, self.font, my_font_size)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

627)                     if part.urgent:
628)                         need_height = len(lines) * self._lineHeight(my_font_size)
629)                         if len(headlines) > 0:
630)                             need_height += len(headlines) * (self._lineHeight(my_font_size) + 1) + self.line_padding
631)                         self.canvas.setFillColorRGB(0.95, 0.95, 0.95)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

632)                         self.canvas.rect(left - 0.5 * cm, self.y - (need_height + (6 * self.line_padding)),
633)                                          height=need_height + (6 * self.line_padding), width=right - left + 1 * cm,
634)                                          fill=1, stroke=1)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

635)                         self.canvas.setFillColorRGB(0, 0, 0)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

636)                         self.y -= self.line_padding * 3
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

637)                     if part.headline and firsttime:
638)                         firsttime = False
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

639)                         self.canvas.setFont(self.font + '-Bold', my_font_size + 1)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

640)                         for line in headlines:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

641)                             self.canvas.drawString(left, self.y - (self.font_height + 1), line)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

642)                             self.y -= self._lineHeight(my_font_size) + 1
643)                         self.y -= self.line_padding
644)                         self.canvas.setFont(self.font, my_font_size)
645)                     for line in lines:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

646)                         self.canvas.drawString(left, self.y - self.font_height, line)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

647)                         self.y -= self._lineHeight(my_font_size)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

648)                     self.y -= self.line_padding * 3
649)             elif isinstance(part, InvoiceImage):
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

650)                 width = (part.imagedata.width / part.dpi) * inch
651)                 height = width * (part.imagedata.height / part.imagedata.width)
652)                 x = self.leftcontent
653)                 if part.alignment == "center":
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

654)                     x = self.leftcontent + (self.rightcontent - self.leftcontent) / 2 - width / 2
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

655)                 elif part.alignment == "right":
656)                     x = self.rightcontent - width
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

657)                 self.canvas.drawInlineImage(part.imagedata, x, self.y - height, width=width, height=height)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

658)                 self.y -= self.line_padding + height
659)                 if part.caption:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

660)                     self.canvas.drawString(x, self.y - self.font_height, part.caption)
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

661)                     self.y -= self._lineHeight()
662)             else:
663)                 raise NotImplementedError("Cannot handle part of type %s" % type(part))
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

664)             self.y -= (0.5 * cm)
665)