ac7fa641d7f0533b7e013a029ed322598e1ff4c8
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) 
Bernd Wurst Alter Copyright-Hinweis ent...

Bernd Wurst authored 4 months ago

11) from . import _formatPrice
Bernd Wurst Test-Script lauffähig

Bernd Wurst authored 4 months ago

12) from .InvoiceObjects import InvoiceTable, InvoiceText, InvoiceImage, GUTSCHRIFT
13) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

28)     ]
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

59)     invoice = None
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

60) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

77) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

96) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

140)             else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

141)                 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

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

Bernd Wurst authored 4 months ago

143)                 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

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

161)         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

167)         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

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

209) 
Bernd Wurst allow for IBAN to be not set

Bernd Wurst authored 4 months ago

210)         if self.invoice.seller_bank_data['iban'] and not self.invoice.debit:
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

211)             iban = self.invoice.seller_bank_data['iban']
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

212)             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

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

Bernd Wurst authored 4 months ago

216)                 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

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

243) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

244)         font_size = 11
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

263) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

292)         self.y = -8.5 * cm
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

293) 
294)     def title(self, title):
295)         self.canvas.setTitle(title)
296)         self.canvas.drawString(self.leftcontent, self.y, title)
297) 
298)     def renderRechnung(self):
299)         self.firstPage()
300)         if self.invoice.tender:
301)             self.canvas.setFont(self.font, self.font_size)
302)             self.canvas.drawString(self.rightcolumn, self.y, "Erstellungsdatum:")
303)             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

304)             self.y -= (self.font_size + 0.1 * cm)
Bernd Wurst allow for type=None (genera...

Bernd Wurst authored 4 months ago

305)         elif self.invoice.type:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

309)             self.canvas.setFont(self.font, self.font_size)
310)             self.canvas.drawString(self.rightcolumn, self.y, "Rechnungsdatum:")
311)             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

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

315)             self.y -= (self.font_size + 0.1 * cm)
Bernd Wurst allow for type=None (genera...

Bernd Wurst authored 4 months ago

316)         else:
Bernd Wurst allow for type=None (genera...

Bernd Wurst authored 4 months ago

317)             self.canvas.setFont(self.font, self.font_size)
Bernd Wurst allow for type=None (genera...

Bernd Wurst authored 4 months ago

318)             self.canvas.drawString(self.rightcolumn, self.y, "Datum:")
319)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.date.strftime('%d. %m. %Y'))
320)             self.y -= (self.font_size + 0.1 * cm)
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

325)         if self.invoice.leitweg_id:
326)             self.canvas.drawString(self.rightcolumn, self.y, "Leitweg-ID:")
327)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.leitweg_id)
328)             self.y -= (self.font_size + 0.1 * cm)
329)         if self.invoice.buyer_reference:
330)             self.canvas.drawString(self.rightcolumn, self.y, "Kunden-Referenz:")
331)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.buyer_reference)
332)             self.y -= (self.font_size + 0.1 * cm)
333)         if self.invoice.contract_number:
334)             self.canvas.drawString(self.rightcolumn, self.y, "Vertragsnummer:")
335)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.contract_number)
336)             self.y -= (self.font_size + 0.1 * cm)
337)         if self.invoice.order_number:
338)             self.canvas.drawString(self.rightcolumn, self.y, "Ihre Bestellnummer:")
339)             self.canvas.drawRightString(self.rightcontent, self.y, "%s" % self.invoice.order_number)
340)             self.y -= (self.font_size + 0.1 * cm)
Bernd Wurst Überschrift unter Datum und...

Bernd Wurst authored 4 months ago

341)         self.canvas.setFont(self.font + '-Bold', self.font_size + 3)
342)         self.title(self.invoice.title)
343)         self.y -= self.font_size + 3 + 0.3 * cm
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

345) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

357)                 self.y -= self.font_size + 0.1 * cm
358)             self.y -= self.font_size + 0.1 * cm
359) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

367)                 left = self.leftcontent
368)                 right = self.rightcontent
369)                 self._tableHead(part)
370)                 temp_sum = 0.0
371)                 odd = True
372)                 for el in part.entries:
373)                     if el['type'] == 'title':
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

378)                         self.canvas.setFont(self.font, font_size)
379)                         self.y -= self.line_height + self.line_padding
380)                     else:
381)                         if len(part.vat) == 1:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

383)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

388)                         if 'period_start' in el and el['period_start']:
389)                             if 'period_end' in el and el['period_end']:
390)                                 desc.extend(self._splitToWidth('Leistungszeitraum: %s - %s' %
391)                                                                (el['period_start'].strftime('%d.%m.%Y'),
392)                                                                 el['period_end'].strftime('%d.%m.%Y')),
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

407)                             # page wrap
408)                             self._PageWrap()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

410)                             # header
411)                             self._tableHead(part)
412)                             self.y -= self.line_padding * 3
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

413)                             odd = True
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

421) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

424) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

425)                         # draw the background
426)                         if not odd:
427)                             self.canvas.setFillColorRGB(0.9, 0.9, 0.9)
428)                         else:
429)                             self.canvas.setFillColorRGB(1, 1, 1)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

435)                         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

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

Bernd Wurst authored 4 months ago

437)                             self.canvas.drawString(left + 1.2 * cm, self.y - self.font_height, el['unit'])
438)                         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

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

442)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

443)                             self.canvas.drawRightString(left + 13.3 * cm, self.y - self.font_height,
444)                                                         _formatPrice(el['price']))
445)                             self.canvas.drawString(left + 13.7 * cm, self.y - self.font_height,
446)                                                    str(part.vat[el['vat']][1]))
447)                         if el['tender']:
448)                             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

449)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

452)                         subject = subject[1:]
453)                         x = 1
454)                         for line in subject:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

457)                             x += 1
458)                         for line in desc:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

461)                             x += 1
462)                         odd = not odd
463)                         self.y -= (need_lines * self.line_height) + self.line_padding
464)                 if part.summary:
465)                     need_lines = 5
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

470)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Zwischensumme:')
471)                         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

472)                         # page wrap
473)                         self._PageWrap()
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

475)                         # header
476)                         self._tableHead(part)
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

477)                         odd = True
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

480)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Übertrag:')
481)                         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

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

487)                             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

488)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

489)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Rechnungsbetrag:')
490)                         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

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

506)                                     else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

510)                                 else:
511)                                     for vat, vatdata in part.vat.items():
512)                                         if vat > 0:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

516)                                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

520)                             summaries.sort()
521)                             for line in summaries:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

522)                                 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

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

Bernd Wurst authored 4 months ago

524)                                     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

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

Bernd Wurst authored 4 months ago

527)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Nettobetrag:')
528)                         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

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

545)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, line[0])
546)                             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

547)                             self.y -= self.line_height
548)                         sum = 0
549)                         for vat, vatdata in part.vat.items():
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

553)                             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

554)                         else:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

555)                             self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height, 'Rechnungsbetrag:')
556)                         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

557)                         self.canvas.setFont(self.font, font_size)
558)                         self.y -= self.line_height + self.line_padding
559)                     paysum = 0.0
560)                     for pay in part.payments:
561)                         paysum += pay['amount']
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

576)                         self.y -= self.line_height
577)                     sum = part.sum
578)                     if part.vatType == 'net':
579)                         sum = 0
580)                         for vat, vatdata in part.vat.items():
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

584)                         self.canvas.setFont(self.font + '-Bold', font_size)
585)                         self.canvas.drawRightString(left + 14.5 * cm, self.y - self.font_height,
586)                                                     'Offener Rechnungsbetrag:')
587)                         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

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

Bernd Wurst authored 4 months ago

590) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

594)                 self.canvas.setFont(self.font, my_font_size)
595)                 left, right = self.leftcontent, self.rightcontent
Bernd Wurst new feature: indentation fo...

Bernd Wurst authored 4 months ago

596)                 indent = 0
597)                 if part.indent:
598)                     if isinstance(part.indent, bool):
599)                         indent = 2 * cm
600)                     else:
601)                         indent = part.indent * cm
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

602)                 firsttime = True
603)                 headlines = []
604)                 if part.urgent:
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

605)                     left += 1.5 * cm
606)                     right -= 1.5 * cm
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

609)                 for para in part.paragraphs:
Bernd Wurst new feature: indentation fo...

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 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 4 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 In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 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 new feature: indentation fo...

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 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 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

641)                 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

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 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 4 months ago

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