b9907381f5b410ff1c46062564fcce6340289ce3
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

1) # -*- coding: utf-8 -*-
2) 
3) import os.path
4) 
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

5) from reportlab.lib.pagesizes import A4
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

6) from reportlab.lib.units import cm, inch
7) from reportlab.pdfbase import pdfmetrics
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

8) from reportlab.pdfbase.ttfonts import TTFont, TTFError
9) from reportlab.pdfgen import canvas
10) 
11) from .InvoiceObjects import InvoiceTable, InvoiceText, InvoiceImage, GUTSCHRIFT
Bernd Wurst Alter Copyright-Hinweis ent...

Bernd Wurst authored 4 months ago

12) from . import _formatPrice
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

13) 
14) def find_font_file(filename):
15)     for n in range(4):
16)         candidate = os.path.abspath(os.path.join(os.path.dirname(__file__), '../' * n, 'ressource/fonts', filename))
17)         if os.path.exists(candidate):
18)             return candidate
19) 
20) 
21) def _registerFonts():
22)     fonts = [
23)         ("DejaVu", "DejaVuSans.ttf"),
24)         ("DejaVu-Bold", "DejaVuSans-Bold.ttf"),
25)         ("DejaVu-Italic", "DejaVuSans-Oblique.ttf"),
26)         ("DejaVu-BoldItalic", "DejaVuSans-BoldOblique.ttf")
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

27)     ]
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

28)     for fontname, fontfile in fonts:
29)         found = False
30)         try:
31)             pdfmetrics.registerFont(TTFont(fontname, fontfile))
32)             found = True
33)         except TTFError:
34)             pass
35)         if not found:
36)             f = find_font_file(fontfile)
37)             if f:
38)                 pdfmetrics.registerFont(TTFont(fontname, f))
39) 
40) 
41) class PDF(object):
42)     # Set default font size
43)     default_font_size = 8
44)     font = 'DejaVu'
45)     # set margins
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

46)     topmargin = 2 * cm
47)     bottommargin = 2.2 * cm
48)     leftmargin = 2 * cm
49)     rightmargin = 2 * cm
50)     rightcolumn = 13 * cm
51) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

52)     canvas = None
53)     num_pages = 1
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

54)     font_height = 0.3 * cm
55)     line_padding = 0.1 * cm
56)     line_height = font_height + 0.1 * cm
57) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

58)     invoice = None
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

59) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

60)     def __init__(self, invoice):
61)         _registerFonts()
62)         from io import BytesIO
63)         self.fd = BytesIO()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

64)         self.canvas = canvas.Canvas(self.fd, pagesize=A4)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

65) 
66)         self.invoice = invoice
67) 
68)         self.topcontent = -self.topmargin
69)         self.leftcontent = self.leftmargin
70)         self.rightcontent = A4[0] - self.rightmargin
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

71)         self.bottomcontent = -(A4[1] - self.bottommargin)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

72) 
73)         self.font_size = 8
74)         self.x = 2.0 * cm
75)         self.y = -4.8 * cm - self.font_size - 1
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

76) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

77)         self.canvas.setFont(self.font, self.font_size)
78) 
79)     def _splitToWidth(self, text, width, font, size):
80)         '''_splitToWidth(canvas, text, width, font, size)
81)         Split a string to several lines of a given width.'''
82)         lines = []
83)         paras = text.split('\n')
84)         for para in paras:
85)             words = para.split(' ')
86)             while len(words) > 0:
87)                 mywords = [words[0], ]
88)                 del words[0]
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

89)                 while len(words) > 0 and self.canvas.stringWidth(' '.join(mywords) + ' ' + words[0], font,
90)                                                                  size) <= width:
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

91)                     mywords.append(words[0])
92)                     del words[0]
93)                 lines.append(' '.join(mywords))
94)         return lines
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

95) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

96)     def _PageMarkers(self):
97)         """Setzt Falzmarken"""
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

98)         self.canvas.setStrokeColor((0, 0, 0))
99)         self.canvas.setLineWidth(0.01 * cm)
100)         self.canvas.lines([(0.3 * cm, -10.5 * cm, 0.65 * cm, -10.5 * cm),
101)                            (0.3 * cm, -21.0 * cm, 0.65 * cm, -21.0 * cm),
102)                            (0.3 * cm, -14.85 * cm, 0.7 * cm, -14.85 * cm)])
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

103) 
104)     def _lineHeight(self, fontsize=None, font=None):
105)         if not fontsize:
106)             fontsize = self.default_font_size
107)         if not font:
108)             font = self.font
109)         face = pdfmetrics.getFont(font).face
110)         string_height = (face.ascent - face.descent) / 1000 * fontsize
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

111)         return string_height + 0.1 * cm
112) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

115)         if isinstance(part, InvoiceText):
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

118)                 left += 1.5 * cm
119)                 right -= 1.5 * cm
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

124)                 height += (len(self._splitToWidth(part.headline, right - left, self.font + '-Bold',
125)                                                   self.default_font_size + 1)) * self.line_height) + self.line_padding
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

127)                 height += (len(self._splitToWidth(para, right - left, self.font,
128)                                                   self.default_font_size)) * self.line_height) + self.line_padding
129)         elif isinstance(part, InvoiceTable):
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

130)             # Eine Zeile plus 2 mal line_padding für Tabellenkopf
131)             height = self.line_height + 2 * self.line_padding
132)             # Wenn nur ein Element (plus Summen) hin passt, reicht uns das
133)             el = part.entries[0]
134)             # Die Abstände oben und unten
135)             height += 2 * self.line_padding
136)             # Die Breite ist konservativ
137)             if el['type'] == 'title':
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

138)                 height += self.line_height + 0.2 * cm
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

139)             else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

140)                 height += self.line_height * len(self._splitToWidth(el['subject'], 9.3 * cm, self.font, self.font_size))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

142)                 height += self.line_height * len(self._splitToWidth(el['desc'], 11 * cm, self.font, self.font_size))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

143)             if part.vatType == 'net':
144)                 # Eine Zeile mehr
145)                 height += self.line_height + self.line_padding
146)             # Für die MwSt-Summen
147)             height += (self.line_height + self.line_padding) * len(part.vat)
148)             # Für den Rechnungsbetrag
149)             height += self.line_height + self.line_padding
150)         return height
151) 
152)     def _tableHead(self, part):
153)         self.canvas.setFont(self.font, self.font_size)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

154)         self.canvas.drawString(self.leftcontent + (0.1 * cm), self.y - self.line_height + self.line_padding, 'Anz.')
155)         self.canvas.drawString(self.leftcontent + (2.1 * cm), self.y - self.line_height + self.line_padding,
156)                                'Beschreibung')
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

158)             self.canvas.drawRightString(self.leftcontent + (14.3 * cm), self.y - self.line_height + self.line_padding,
159)                                         'Einzelpreis')
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

160)         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

161)             self.canvas.drawRightString(self.leftcontent + (13.3 * cm), self.y - self.line_height + self.line_padding,
162)                                         'Einzelpreis')
163)         self.canvas.drawRightString(self.leftcontent + (16.8 * cm), self.y - self.line_height + self.line_padding,
164)                                     'Gesamtpreis')
165)         self.canvas.setLineWidth(0.01 * cm)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

167)         self.y -= self.line_height + 0.02 * cm
168) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

169)     def _PageWrap(self):
170)         '''Seitenumbruch'''
171)         self.num_pages += 1
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

172)         self.canvas.setFont(self.font, self.default_font_size - 2)
173)         self.canvas.drawRightString(self.rightcontent, self.bottomcontent + self.line_padding,
174)                                     'Fortsetzung auf Seite %i' % self.num_pages)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

175)         self.canvas.showPage()
176)         self.basicPage()
177)         self.y = self.topcontent - self.font_size
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

178)         self.canvas.setFillColor((0, 0, 0))
179)         self.canvas.setFont(self.font, self.font_size - 2)
180)         self.canvas.drawCentredString(self.leftcontent + (self.rightcontent - self.leftcontent) / 2, self.y,
181)                                       '- Seite %i -' % self.num_pages)
182) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

185)         self.canvas.setFillColor((0, 0, 0))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

186)         self.canvas.line(self.leftcontent, self.bottomcontent, self.rightcontent, self.bottomcontent)
187)         self.canvas.setFont(self.font, 7)
188)         lines = list(filter(None, [
189)             self.invoice.seller['trade_name'],
190)             self.invoice.seller['name'] if self.invoice.seller['trade_name'] else None,
191)             self.invoice.seller['website'],
192)             self.invoice.seller['email'],
193)         ]))
194)         c = 0
195)         for line in lines:
196)             c += 10
197)             self.canvas.drawString(self.leftcontent, self.bottomcontent - c, line)
198) 
199)         if self.invoice.seller_vat_id:
200)             lines = list(filter(None, [
201)                 "USt-ID: " + self.invoice.seller_vat_id
202)             ]))
203)             c = 0
204)             for line in lines:
205)                 c += 10
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

206)                 self.canvas.drawString(self.leftcontent + ((self.rightcontent - self.leftcontent) // 3),
207)                                        self.bottomcontent - c, line)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

208) 
209)         if not self.invoice.debit:
210)             iban = self.invoice.seller_bank_data['iban']
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

211)             iban = ' '.join([iban[i:i + 4] for i in range(0, len(iban), 4)])
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

215)                 f"BIC: {self.invoice.seller_bank_data['bic']}" if self.invoice.seller_bank_data['bic'] else None,
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

216)             ]
217)             c = 0
218)             for line in lines:
219)                 c += 10
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

220)                 self.canvas.drawString(self.leftcontent + ((self.rightcontent - self.leftcontent) // 3) * 2,
221)                                        self.bottomcontent - c, line)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

222) 
223)     def basicPage(self):
224)         # Set marker to top.
225)         self.canvas.translate(0, A4[1])
226) 
227)         self._PageMarkers()
228)         self._Footer()
229) 
230)     def addressBox(self):
231)         lines = [
232)             self.invoice.seller['trade_name'],
233)             self.invoice.seller['address']['line1'],
234)             self.invoice.seller['address']['line2'],
235)             self.invoice.seller['address']['line3'],
236)             self.invoice.seller['address']['postcode'] + ' ' + self.invoice.seller['address']['city_name'],
237)         ]
238)         address = ' · '.join(filter(None, lines))
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

239)         self.canvas.drawString(self.x, self.y + 0.1 * cm, f' {address}')
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

242) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

243)         font_size = 11
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

244)         x = self.x + 0.5 * cm
245)         self.y -= 0.5 * cm
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

246)         self.canvas.setFont(self.font, font_size)
247)         addresslines = filter(None, [
248)             self.invoice.customer['name'].strip(),
249)             self.invoice.customer['address']['line1'] or '',
250)             self.invoice.customer['address']['line2'] or '',
251)             self.invoice.customer['address']['line3'] or '',
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

252)             ((self.invoice.customer['address']['postcode'] or '') + ' ' + (
253)                     self.invoice.customer['address']['city_name'] or '')).strip(),
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

254)         ])
255)         for line in addresslines:
256)             self.canvas.drawString(x, self.y, line)
257)             self.y -= font_size * 0.03527 * cm * 1.2
258) 
259)     def firstPage(self):
260)         self.basicPage()
261)         self.addressBox()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

262) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

264)         self.canvas.drawImage(self.invoice.logo_image_file, self.rightcolumn, self.topcontent - (2 * cm),
265)                               height=2 * cm, preserveAspectRatio=True, anchor='nw')
266)         self.y -= (2.5 * cm)
267)         self.canvas.setFont(self.font + "-Bold", self.font_size)
268)         self.canvas.drawString(self.rightcolumn, self.y,
269)                                self.invoice.seller['trade_name'] or self.invoice.seller['name'])
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

270)         self.y -= (self.font_size + 5)
271)         self.canvas.setFont(self.font, self.font_size)
272)         lines = [
273)             self.invoice.seller['name'] if self.invoice.seller['trade_name'] else None,
274)             self.invoice.seller['address']['line1'],
275)             self.invoice.seller['address']['line2'],
276)             self.invoice.seller['address']['line3'],
277)             self.invoice.seller['address']['postcode'] + ' ' + self.invoice.seller['address']['city_name'],
278)             self.invoice.seller['website'],
279)         ]
280)         address = filter(None, lines)
281)         for line in address:
282)             self.canvas.drawString(self.rightcolumn, self.y, line)
283)             self.y -= (self.font_size + 5)
284)         self.y -= 5
Bernd Wurst WiP

Bernd Wurst authored 4 months ago

285)         if self.invoice.seller['phone']:
286)             self.canvas.drawString(self.rightcolumn, self.y, f"Tel: {self.invoice.seller['phone']}")
287)             self.y -= (self.font_size + 5)
288)         if self.invoice.seller['email']:
289)             self.canvas.drawString(self.rightcolumn, self.y, f"E-Mail: {self.invoice.seller['email']}")
290)             self.y -= (self.font_size + 10)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

291)         self.y = -9.5 * cm
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

292) 
293)     def title(self, title):
294)         self.canvas.setTitle(title)
295)         self.canvas.drawString(self.leftcontent, self.y, title)
296) 
297)     def renderRechnung(self):
298)         self.firstPage()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

299)         self.canvas.setFont(self.font + '-Bold', self.font_size + 3)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

300)         self.title(self.invoice.title)
301) 
302)         if self.invoice.tender:
303)             self.canvas.setFont(self.font, self.font_size)
304)             self.canvas.drawString(self.rightcolumn, self.y, "Erstellungsdatum:")
305)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.date.strftime('%d. %m. %Y'))
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

306)             self.y -= (self.font_size + 0.1 * cm)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

307)         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

308)             self.canvas.setFont(self.font + '-Bold', self.font_size)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

310)             self.y -= (self.font_size + 0.2 * cm)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

314)             self.y -= (self.font_size + 0.1 * cm)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

317)             self.y -= (self.font_size + 0.1 * cm)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

322)         if self.invoice.leitweg_id:
323)             self.canvas.drawString(self.rightcolumn, self.y, "Leitweg-ID:")
324)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.leitweg_id)
325)             self.y -= (self.font_size + 0.1 * cm)
326)         if self.invoice.buyer_reference:
327)             self.canvas.drawString(self.rightcolumn, self.y, "Kunden-Referenz:")
328)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.buyer_reference)
329)             self.y -= (self.font_size + 0.1 * cm)
330)         if self.invoice.contract_number:
331)             self.canvas.drawString(self.rightcolumn, self.y, "Vertragsnummer:")
332)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.contract_number)
333)             self.y -= (self.font_size + 0.1 * cm)
334)         if self.invoice.order_number:
335)             self.canvas.drawString(self.rightcolumn, self.y, "Ihre Bestellnummer:")
336)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.order_number)
337)             self.y -= (self.font_size + 0.1 * cm)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

339) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

342)             self.y -= self.font_size + 0.2 * cm
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

346)             if self.invoice.type == GUTSCHRIFT:
347)                 introText = 'nach unserer Berechnung entsteht für Sie folgende Gutschrift.'
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

351)                 self.y -= self.font_size + 0.1 * cm
352)             self.y -= self.font_size + 0.1 * cm
353) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

356)             if self.y - self._partHeight(part) < (self.bottomcontent + (0.5 * cm)):
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

358)                 self.y = self.topcontent - self.font_size - self.line_padding * 3
359)             if isinstance(part, InvoiceTable):
360) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

361)                 left = self.leftcontent
362)                 right = self.rightcontent
363)                 self._tableHead(part)
364)                 temp_sum = 0.0
365)                 odd = True
366)                 for el in part.entries:
367)                     if el['type'] == 'title':
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

368)                         self.y -= self.line_padding + 0.2 * cm
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

370)                         self.canvas.setFont(self.font + '-Italic', font_size)
371)                         self.canvas.drawString(left, self.y - self.font_height, el['title'])
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

372)                         self.canvas.setFont(self.font, font_size)
373)                         self.y -= self.line_height + self.line_padding
374)                     else:
375)                         if len(part.vat) == 1:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

376)                             subject = self._splitToWidth(el['subject'], 9.8 * cm, self.font, font_size)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

377)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

378)                             subject = self._splitToWidth(el['subject'], 8.8 * cm, self.font, font_size)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

381)                             desc = self._splitToWidth(el['desc'], 14.0 * cm, self.font, font_size)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

382)                         if 'period_start' in el and el['period_start']:
383)                             if 'period_end' in el and el['period_end']:
384)                                 desc.extend(self._splitToWidth('Leistungszeitraum: %s - %s' %
385)                                                                (el['period_start'].strftime('%d.%m.%Y'),
386)                                                                 el['period_end'].strftime('%d.%m.%Y')),
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

387)                                                                14.0 * cm, self.font, font_size))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

391)                                                                14.0 * cm, self.font, font_size))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

394)                         if self.y - (need_lines + 1 * (self.line_height + self.line_padding)) < (
395)                                 self.bottomcontent + 1 * cm):
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

398)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Zwischensumme:')
399)                             self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height,
400)                                                         _formatPrice(temp_sum))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

401)                             # page wrap
402)                             self._PageWrap()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

403)                             self.y = self.topcontent - font_size - self.line_padding * 3
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

404)                             # header
405)                             self._tableHead(part)
406)                             self.y -= self.line_padding * 3
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

407)                             odd = True
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

410)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Übertrag:')
411)                             self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height,
412)                                                         _formatPrice(temp_sum))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

415) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

418) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

419)                         # draw the background
420)                         if not odd:
421)                             self.canvas.setFillColorRGB(0.9, 0.9, 0.9)
422)                         else:
423)                             self.canvas.setFillColorRGB(1, 1, 1)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

424)                         self.canvas.rect(left, self.y - (need_lines * self.line_height) - (2 * self.line_padding),
425)                                          height=(need_lines * self.line_height) + (2 * self.line_padding),
426)                                          width=right - left, fill=1, stroke=0)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

429)                         self.canvas.drawRightString(left + 1.1 * cm, self.y - self.font_height, '%.0f' % el['count'])
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

431)                             self.canvas.drawString(left + 1.2 * cm, self.y - self.font_height, el['unit'])
432)                         self.canvas.drawString(left + 2.2 * cm, self.y - self.font_height, subject[0])
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

434)                             self.canvas.drawRightString(left + 14.3 * cm, self.y - self.font_height,
435)                                                         _formatPrice(el['price']))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

436)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

437)                             self.canvas.drawRightString(left + 13.3 * cm, self.y - self.font_height,
438)                                                         _formatPrice(el['price']))
439)                             self.canvas.drawString(left + 13.7 * cm, self.y - self.font_height,
440)                                                    str(part.vat[el['vat']][1]))
441)                         if el['tender']:
442)                             self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, 'eventual')
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

443)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

444)                             self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height,
445)                                                         _formatPrice(el['total']))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

446)                         subject = subject[1:]
447)                         x = 1
448)                         for line in subject:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

449)                             self.canvas.drawString(left + 2.2 * cm, self.y - (x * self.line_height) - self.font_height,
450)                                                    line)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

451)                             x += 1
452)                         for line in desc:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

453)                             self.canvas.drawString(left + 2.2 * cm, self.y - (x * self.line_height) - self.font_height,
454)                                                    line)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

455)                             x += 1
456)                         odd = not odd
457)                         self.y -= (need_lines * self.line_height) + self.line_padding
458)                 if part.summary:
459)                     need_lines = 5
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

460)                     if self.y - (need_lines + 1 * (self.line_height + self.line_padding)) < (
461)                             self.bottomcontent + 1 * cm):
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

464)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Zwischensumme:')
465)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, _formatPrice(temp_sum))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

466)                         # page wrap
467)                         self._PageWrap()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

468)                         self.y = self.topcontent - font_size - self.line_padding * 3
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

469)                         # header
470)                         self._tableHead(part)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

471)                         odd = True
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

474)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Übertrag:')
475)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, _formatPrice(temp_sum))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

477)                     self.y -= (0.3 * cm)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

479)                         self.canvas.setFont(self.font + '-Bold', font_size)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

481)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Gesamtbetrag:')
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

482)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

483)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Rechnungsbetrag:')
484)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, _formatPrice(part.sum))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

485)                         if self.invoice.official:
486)                             self.canvas.setFont(self.font, font_size)
487)                             self.y -= self.line_height + self.line_padding
488)                             summaries = []
489)                             vat = 0.0
490)                             if len(part.vat) == 1 and list(part.vat.keys())[0] == 0.0:
491)                                 self.canvas.drawString(left, self.y - self.font_height,
492)                                                        'Dieser Beleg wurde ohne Ausweis von MwSt erstellt.')
493)                                 self.y -= self.line_height
494)                             else:
495)                                 if len(part.vat) == 1:
496)                                     vat = list(part.vat.keys())[0]
497)                                     if self.invoice.tender:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

498)                                         summaries.append(('Im Gesamtbetrag sind %.1f%% MwSt enthalten:' % (vat * 100),
499)                                                           _formatPrice((part.sum / (vat + 1)) * vat)))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

500)                                     else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

501)                                         summaries.append((
502)                                             'Im Rechnungsbetrag sind %.1f%% MwSt enthalten:' % (vat * 100),
503)                                             _formatPrice((part.sum / (vat + 1)) * vat)))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

504)                                 else:
505)                                     for vat, vatdata in part.vat.items():
506)                                         if vat > 0:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

507)                                             summaries.append(('%s: Im Teilbetrag von %s sind %.1f%% MwSt enthalten:' % (
508)                                                 vatdata[1], _formatPrice(vatdata[0]), vat * 100),
509)                                                               _formatPrice((vatdata[0] / (vat + 1)) * vat)))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

510)                                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

511)                                             summaries.append(('%s: Durchlaufende Posten ohne Berechnung von MwSt.' % (
512)                                                 vatdata[1]), 0.0))
513)                             summaries.append(('Nettobetrag:', _formatPrice(part.sum - (part.sum / (vat + 1)) * vat)))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

514)                             summaries.sort()
515)                             for line in summaries:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

516)                                 self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, line[0])
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

518)                                     self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, line[1])
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

521)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Nettobetrag:')
522)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, _formatPrice(part.sum))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

523)                         self.y -= self.line_height
524)                         summaries = []
525)                         if list(part.vat.keys())[0] == 0.0:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

526)                             self.canvas.drawString(left, self.y - self.font_height,
527)                                                    'Dieser Beleg wurde ohne Ausweis von MwSt erstellt.')
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

528)                             self.y -= self.line_height
529)                         else:
530)                             if len(part.vat) == 1:
531)                                 vat = list(part.vat.keys())[0]
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

532)                                 summaries.append(('zzgl. %.1f%% MwSt:' % (vat * 100), _formatPrice(vat * part.sum)))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

535)                                     summaries.append(('zzgl. %.1f%% MwSt (%s):' % (vat * 100, vatdata[1]),
536)                                                       _formatPrice(vat * vatdata[0])))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

537)                         summaries.sort()
538)                         for line in summaries:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

539)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, line[0])
540)                             self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, line[1])
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

541)                             self.y -= self.line_height
542)                         sum = 0
543)                         for vat, vatdata in part.vat.items():
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

544)                             sum += (vat + 1) * vatdata[0]
545)                         self.canvas.setFont(self.font + '-Bold', font_size)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

547)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Gesamtbetrag:')
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

548)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

549)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Rechnungsbetrag:')
550)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, _formatPrice(sum))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

551)                         self.canvas.setFont(self.font, font_size)
552)                         self.y -= self.line_height + self.line_padding
553)                     paysum = 0.0
554)                     for pay in part.payments:
555)                         paysum += pay['amount']
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

556)                         descr = 'Zahlung'
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

557)                         if pay['type'] == 'cash':
558)                             descr = 'gegeben'
559)                         elif pay['type'] == 'return':
560)                             descr = 'zurück'
561)                         elif pay['type'] == 'ec':
562)                             descr = 'Kartenzahlung (EC)'
563)                         elif pay['type'] == 'gutschein':
564)                             descr = 'Einlösung Gutschein'
565)                         if pay['date'] != self.invoice.date:
566)                             descr += ' am %s' % (pay['date'].strftime('%d. %m. %Y'))
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

567)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, descr + ':')
568)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height,
569)                                                     _formatPrice(pay['amount']))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

570)                         self.y -= self.line_height
571)                     sum = part.sum
572)                     if part.vatType == 'net':
573)                         sum = 0
574)                         for vat, vatdata in part.vat.items():
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

575)                             sum += (vat + 1) * vatdata[0]
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

578)                         self.canvas.setFont(self.font + '-Bold', font_size)
579)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height,
580)                                                     'Offener Rechnungsbetrag:')
581)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, _formatPrice(rest))
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

584) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

586)             elif isinstance(part, InvoiceText):
587)                 my_font_size = font_size + part.fontsize  # Relative Schriftgröße beachten
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

588)                 self.canvas.setFont(self.font, my_font_size)
589)                 left, right = self.leftcontent, self.rightcontent
590)                 firsttime = True
591)                 headlines = []
592)                 if part.urgent:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

593)                     left += 1.5 * cm
594)                     right -= 1.5 * cm
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

596)                     headlines = self._splitToWidth(part.headline, right - left, self.font, my_font_size)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

598)                     lines = self._splitToWidth(para, right - left, self.font, my_font_size)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

599)                     if part.urgent:
600)                         need_height = len(lines) * self._lineHeight(my_font_size)
601)                         if len(headlines) > 0:
602)                             need_height += len(headlines) * (self._lineHeight(my_font_size) + 1) + self.line_padding
603)                         self.canvas.setFillColorRGB(0.95, 0.95, 0.95)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

604)                         self.canvas.rect(left - 0.5 * cm, self.y - (need_height + (6 * self.line_padding)),
605)                                          height=need_height + (6 * self.line_padding), width=right - left + 1 * cm,
606)                                          fill=1, stroke=1)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

608)                         self.y -= self.line_padding * 3
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

609)                     if part.headline and firsttime:
610)                         firsttime = False
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

611)                         self.canvas.setFont(self.font + '-Bold', my_font_size + 1)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

613)                             self.canvas.drawString(left, self.y - (self.font_height + 1), line)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

614)                             self.y -= self._lineHeight(my_font_size) + 1
615)                         self.y -= self.line_padding
616)                         self.canvas.setFont(self.font, my_font_size)
617)                     for line in lines:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

618)                         self.canvas.drawString(left, self.y - self.font_height, line)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

620)                     self.y -= self.line_padding * 3
621)             elif isinstance(part, InvoiceImage):
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

622)                 width = (part.imagedata.width / part.dpi) * inch
623)                 height = width * (part.imagedata.height / part.imagedata.width)
624)                 x = self.leftcontent
625)                 if part.alignment == "center":
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

626)                     x = self.leftcontent + (self.rightcontent - self.leftcontent) / 2 - width / 2
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

629)                 self.canvas.drawInlineImage(part.imagedata, x, self.y - height, width=width, height=height)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

632)                     self.canvas.drawString(x, self.y - self.font_height, part.caption)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

636)             self.y -= (0.5 * cm)
637)