a43c0b864661fd3e9de3b48c530c95e6535f0117
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 WiP

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

351) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

363)                 self.y -= self.font_size + 0.1 * cm
364)             self.y -= self.font_size + 0.1 * cm
365) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

370)                 self.y = self.topcontent - self.font_size - self.line_padding * 3
371)             if isinstance(part, InvoiceTable):
372) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

373)                 left = self.leftcontent
374)                 right = self.rightcontent
375)                 self._tableHead(part)
376)                 temp_sum = 0.0
377)                 odd = True
378)                 for el in part.entries:
379)                     if el['type'] == 'title':
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

384)                         self.canvas.setFont(self.font, font_size)
385)                         self.y -= self.line_height + self.line_padding
386)                     else:
387)                         if len(part.vat) == 1:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

389)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

394)                         if 'period_start' in el and el['period_start']:
395)                             if 'period_end' in el and el['period_end']:
396)                                 desc.extend(self._splitToWidth('Leistungszeitraum: %s - %s' %
397)                                                                (el['period_start'].strftime('%d.%m.%Y'),
398)                                                                 el['period_end'].strftime('%d.%m.%Y')),
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

413)                             # page wrap
414)                             self._PageWrap()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

416)                             # header
417)                             self._tableHead(part)
418)                             self.y -= self.line_padding * 3
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

419)                             odd = True
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

427) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

430) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

431)                         # draw the background
432)                         if not odd:
433)                             self.canvas.setFillColorRGB(0.9, 0.9, 0.9)
434)                         else:
435)                             self.canvas.setFillColorRGB(1, 1, 1)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

448)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

449)                             self.canvas.drawRightString(left + 13.3 * cm, self.y - self.font_height,
450)                                                         _formatPrice(el['price']))
451)                             self.canvas.drawString(left + 13.7 * cm, self.y - self.font_height,
452)                                                    str(part.vat[el['vat']][1]))
453)                         if el['tender']:
454)                             self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, 'eventual')
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

455)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

458)                         subject = subject[1:]
459)                         x = 1
460)                         for line in subject:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

463)                             x += 1
464)                         for line in desc:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

467)                             x += 1
468)                         odd = not odd
469)                         self.y -= (need_lines * self.line_height) + self.line_padding
470)                 if part.summary:
471)                     need_lines = 5
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

478)                         # page wrap
479)                         self._PageWrap()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

481)                         # header
482)                         self._tableHead(part)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

483)                         odd = True
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

494)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

497)                         if self.invoice.official:
498)                             self.canvas.setFont(self.font, font_size)
499)                             self.y -= self.line_height + self.line_padding
500)                             summaries = []
501)                             vat = 0.0
502)                             if len(part.vat) == 1 and list(part.vat.keys())[0] == 0.0:
503)                                 self.canvas.drawString(left, self.y - self.font_height,
504)                                                        'Dieser Beleg wurde ohne Ausweis von MwSt erstellt.')
505)                                 self.y -= self.line_height
506)                             else:
507)                                 if len(part.vat) == 1:
508)                                     vat = list(part.vat.keys())[0]
509)                                     if self.invoice.tender:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

512)                                     else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

516)                                 else:
517)                                     for vat, vatdata in part.vat.items():
518)                                         if vat > 0:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

522)                                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

526)                             summaries.sort()
527)                             for line in summaries:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

535)                         self.y -= self.line_height
536)                         summaries = []
537)                         if list(part.vat.keys())[0] == 0.0:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

540)                             self.y -= self.line_height
541)                         else:
542)                             if len(part.vat) == 1:
543)                                 vat = list(part.vat.keys())[0]
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

549)                         summaries.sort()
550)                         for line in summaries:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

553)                             self.y -= self.line_height
554)                         sum = 0
555)                         for vat, vatdata in part.vat.items():
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

560)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

563)                         self.canvas.setFont(self.font, font_size)
564)                         self.y -= self.line_height + self.line_padding
565)                     paysum = 0.0
566)                     for pay in part.payments:
567)                         paysum += pay['amount']
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

568)                         descr = 'Zahlung'
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

569)                         if pay['type'] == 'cash':
570)                             descr = 'gegeben'
571)                         elif pay['type'] == 'return':
572)                             descr = 'zurück'
573)                         elif pay['type'] == 'ec':
574)                             descr = 'Kartenzahlung (EC)'
575)                         elif pay['type'] == 'gutschein':
576)                             descr = 'Einlösung Gutschein'
577)                         if pay['date'] != self.invoice.date:
578)                             descr += ' am %s' % (pay['date'].strftime('%d. %m. %Y'))
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

582)                         self.y -= self.line_height
583)                     sum = part.sum
584)                     if part.vatType == 'net':
585)                         sum = 0
586)                         for vat, vatdata in part.vat.items():
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

590)                         self.canvas.setFont(self.font + '-Bold', font_size)
591)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height,
592)                                                     'Offener Rechnungsbetrag:')
593)                         self.canvas.drawRightString(left + 16.8 * cm, self.y - self.font_height, _formatPrice(rest))
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

596) 
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

600)                 self.canvas.setFont(self.font, my_font_size)
601)                 left, right = self.leftcontent, self.rightcontent
602)                 firsttime = True
603)                 headlines = []
604)                 if part.urgent:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

605)                     left += 1.5 * cm
606)                     right -= 1.5 * cm
Bernd Wurst WiP

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

611)                     if part.urgent:
612)                         need_height = len(lines) * self._lineHeight(my_font_size)
613)                         if len(headlines) > 0:
614)                             need_height += len(headlines) * (self._lineHeight(my_font_size) + 1) + self.line_padding
615)                         self.canvas.setFillColorRGB(0.95, 0.95, 0.95)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

621)                     if part.headline and firsttime:
622)                         firsttime = False
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

626)                             self.y -= self._lineHeight(my_font_size) + 1
627)                         self.y -= self.line_padding
628)                         self.canvas.setFont(self.font, my_font_size)
629)                     for line in lines:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

634)                 width = (part.imagedata.width / part.dpi) * inch
635)                 height = width * (part.imagedata.height / part.imagedata.width)
636)                 x = self.leftcontent
637)                 if part.alignment == "center":
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

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

Bernd Wurst authored 9 months ago

648)             self.y -= (0.5 * cm)
649)