Alter Copyright-Hinweis entfernt
Bernd Wurst

Bernd Wurst commited on 2024-02-14 13:08:33
Zeige 5 geänderte Dateien mit 38 Einfügungen und 72 Löschungen.

... ...
@@ -1,20 +1,4 @@
1 1
 # -* coding: utf8 *-
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 2
 
19 3
 import datetime
20 4
 
... ...
@@ -1,43 +1,15 @@
1 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 2
 
19 3
 import os.path
20
-import re
21 4
 
22 5
 from reportlab.lib.pagesizes import A4
23
-# reportlab imports
24 6
 from reportlab.lib.units import cm, inch
25 7
 from reportlab.pdfbase import pdfmetrics
26 8
 from reportlab.pdfbase.ttfonts import TTFont, TTFError
27 9
 from reportlab.pdfgen import canvas
28 10
 
29 11
 from .InvoiceObjects import InvoiceTable, InvoiceText, InvoiceImage, GUTSCHRIFT
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)
39
-    return s + ' ' + symbol
40
-
12
+from . import _formatPrice
41 13
 
42 14
 def find_font_file(filename):
43 15
     for n in range(4):
... ...
@@ -2,7 +2,7 @@
2 2
 
3 3
 from __future__ import division
4 4
 
5
-from utils import format_price, split_to_width
5
+from . import _formatPrice, split_to_width
6 6
 from .InvoiceObjects import Invoice, InvoiceTable, InvoiceText, InvoiceImage, PAYMENT_UEBERWEISUNG
7 7
 
8 8
 
... ...
@@ -85,14 +85,14 @@ def InvoiceTableToText(invoiceTable: InvoiceTable):
85 85
         if len(invoiceTable.vat) < 2:
86 86
             subject = _breakLine(el['subject'], width=39)
87 87
             ret.append(u'%5.2f %-3s %-39s  %10s %10s' % (
88
-                el['count'], unit, subject[0], format_price(el['price']), format_price(el['total'])))
88
+                el['count'], unit, subject[0], _formatPrice(el['price']), _formatPrice(el['total'])))
89 89
             for i in range(1, len(subject)):
90 90
                 ret.append(u'          %s' % subject[i])
91 91
         else:
92 92
             subject = _breakLine(el['subject'], width=41)
93 93
             ret.append(u'%5.2f %-3s %-37s  %10s %s %10s' % (
94
-                el['count'], unit, subject[0], format_price(el['price']), invoiceTable.vat[el['vat']][1],
95
-                format_price(el['total'])))
94
+                el['count'], unit, subject[0], _formatPrice(el['price']), invoiceTable.vat[el['vat']][1],
95
+                _formatPrice(el['total'])))
96 96
             for i in range(1, len(subject)):
97 97
                 ret.append(u'          %s' % subject[i])
98 98
         if 'period_start' in el and el['period_start']:
... ...
@@ -111,30 +111,30 @@ def InvoiceTableToText(invoiceTable: InvoiceTable):
111 111
                 ret.append(u'          %s' % line)
112 112
     ret.append('-' * 72)
113 113
     if invoiceTable.vatType == 'gross':
114
-        ret.append((u'Rechnungsbetrag:  %11s' % format_price(invoiceTable.sum)).rjust(72))
114
+        ret.append((u'Rechnungsbetrag:  %11s' % _formatPrice(invoiceTable.sum)).rjust(72))
115 115
         ret.append('')
116 116
         summaries = []
117 117
         if len(invoiceTable.vat) == 1:
118 118
             vat = list(invoiceTable.vat.keys())[0]
119 119
             summaries.append(u'      Im Rechnungsbetrag sind %.1f%% MwSt enthalten (%s)' % (
120
-                vat * 100, format_price((invoiceTable.sum / (vat + 1)) * vat)))
120
+                vat * 100, _formatPrice((invoiceTable.sum / (vat + 1)) * vat)))
121 121
         else:
122 122
             for vat, vatdata in list(invoiceTable.vat.items()):
123 123
                 summaries.append(u'    %s: Im Teilbetrag von %s sind %.1f%% MwSt enthalten (%s)' % (
124
-                    vatdata[1], format_price(vatdata[0]), vat * 100, format_price((vatdata[0] / (vat + 1)) * vat)))
124
+                    vatdata[1], _formatPrice(vatdata[0]), vat * 100, _formatPrice((vatdata[0] / (vat + 1)) * vat)))
125 125
         summaries.sort()
126 126
         for line in summaries:
127 127
             ret.append(line)
128 128
     else:
129
-        ret.append((u'Nettobetrag: %11s' % format_price(invoiceTable.sum)).rjust(72))
129
+        ret.append((u'Nettobetrag: %11s' % _formatPrice(invoiceTable.sum)).rjust(72))
130 130
         summaries = []
131 131
         if len(invoiceTable.vat) == 1:
132 132
             vat = list(invoiceTable.vat.keys())[0]
133
-            summaries.append((u'zzgl. %.1f%% MwSt: %11s' % (vat * 100, format_price(vat * invoiceTable.sum))).rjust(72))
133
+            summaries.append((u'zzgl. %.1f%% MwSt: %11s' % (vat * 100, _formatPrice(vat * invoiceTable.sum))).rjust(72))
134 134
         elif len(invoiceTable.vat) > 1:
135 135
             for vat, vatdata in list(invoiceTable.vat.items()):
136 136
                 summaries.append(
137
-                    (u'zzgl. %4.1f%% MwSt (%s): %11s' % (vat * 100, vatdata[1], format_price(vat * vatdata[0]))).rjust(
137
+                    (u'zzgl. %4.1f%% MwSt (%s): %11s' % (vat * 100, vatdata[1], _formatPrice(vat * vatdata[0]))).rjust(
138 138
                         72))
139 139
         summaries.sort()
140 140
         for line in summaries:
... ...
@@ -142,7 +142,7 @@ def InvoiceTableToText(invoiceTable: InvoiceTable):
142 142
         tablesum = invoiceTable.sum
143 143
         for vat, vatdata in list(invoiceTable.vat.items()):
144 144
             tablesum += vat * vatdata[0]
145
-        ret.append((u'Rechnungsbetrag: %11s' % format_price(tablesum)).rjust(72))
145
+        ret.append((u'Rechnungsbetrag: %11s' % _formatPrice(tablesum)).rjust(72))
146 146
     ret.append('')
147 147
     return '\n'.join(ret)
148 148
 
... ...
@@ -1,20 +1,4 @@
1 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 2
 
19 3
 import os.path
20 4
 import sys
... ...
@@ -0,0 +1,26 @@
1
+
2
+def _formatPrice(price, symbol='€'):
3
+    '''_formatPrice(price, symbol='€'):
4
+    Gets a floating point value and returns a formatted price, suffixed by 'symbol'. '''
5
+    s = ("%.2f" % price).replace('.', ',')
6
+    pat = re.compile(r'([0-9])([0-9]{3}[.,])')
7
+    while pat.search(s):
8
+        s = pat.sub(r'\1.\2', s)
9
+    return s + ' ' + symbol
10
+
11
+
12
+def split_to_width(s, length):
13
+    '''Fügt zeilenumbrüche in einen String ein, dass er maximal 'length' Zeichen lang ist'''
14
+    orig = s
15
+    ret = []
16
+    while len(s) > 0:
17
+        if len(s) < length:
18
+            ret.append(s)
19
+            s = ''
20
+        else:
21
+            index = s.rfind(' ', 0, length)
22
+            if index == -1:
23
+                index = length
24
+            ret.append(s[:index])
25
+            s = s[index + 1:]
26
+    return ret
0 27