Bernd Wurst

Bernd Wurst commited on 2024-01-26 13:03:14
Zeige 1 geänderte Dateien mit 25 Einfügungen und 15 Löschungen.

... ...
@@ -1,7 +1,8 @@
1 1
 # -* coding: utf8 *-
2 2
 
3 3
 from __future__ import division
4
-from Invoice import Text, Table, Image
4
+
5
+from .InvoiceObjects import Invoice, InvoiceTable, InvoiceText, InvoiceImage, PAYMENT_UEBERWEISUNG
5 6
 from utils import format_price, split_to_width
6 7
 
7 8
 
... ...
@@ -20,37 +21,46 @@ def _breakLine(text, width=72):
20 21
     return lines
21 22
 
22 23
 
23
-def InvoiceToText(iv, bankdata=True):
24
+def InvoiceToText(invoice : Invoice, bankdata=True):
24 25
     ret = []
25 26
     ret.append(u'Rechnungsempfänger:')
26
-    for line in iv.addresslines:
27
-        ret.append('  %s' % line)
27
+    addresslines = filter(None, [
28
+        invoice.customer['name'].strip(),
29
+        invoice.customer['address']['line1'] or '',
30
+        invoice.customer['address']['line2'] or '',
31
+        invoice.customer['address']['line3'] or '',
32
+        ((invoice.customer['address']['postcode'] or '') + ' ' + (
33
+                    invoice.customer['address']['city_name'] or '')).strip(),
34
+    ])
35
+    for line in addresslines:
36
+        ret.append(f'  {line}')
28 37
     ret.append('')
29
-    ret.append('Kundennummer:    %4i' % iv.customerno)
30
-    ret.append('Rechnungsnummer: %4i    Rechnungsdatum:  %s' % (iv.id, iv.date.strftime('%d.%m.%Y')))
38
+    ret.append(f'Kundennummer:    {invoice.customerno}')
39
+    ret.append(f'Rechnungsnummer: {invoice.id}')
40
+    ret.append(f'Rechnungsdatum:  {invoice.date.strftime("%d.%m.%Y")}')
31 41
 
32 42
     ret.append('')
33
-    for part in iv.parts:
34
-        if type(part) == Table:
43
+    for part in invoice.parts:
44
+        if type(part) == InvoiceTable:
35 45
             ret.append(InvoiceTableToText(part))
36
-        elif type(part) == Text:
46
+        elif type(part) == InvoiceText:
37 47
             ret.append(InvoiceTextToText(part))
38
-        elif type(part) == Image:
48
+        elif type(part) == InvoiceImage:
39 49
             # ignore images
40 50
             pass
41 51
         else:
42 52
             raise NotImplementedError("Cannot handle part of type %s" % type(part))
43 53
 
44
-    if bankdata:
54
+    if invoice.payment_type == PAYMENT_UEBERWEISUNG:
45 55
         ret.append('-' * 72)
46 56
         ret.append('Unsere Bankverbindung:')
47
-        ret.append('Volksbank Backnang, BLZ 602 911 20, Konto-Nr. 41512 006')
48
-        ret.append('IBAN: DE91602911200041512006, BIC: GENODES1VBK')
57
+        ret.append(f'{invoice.seller_bank_data["bankname"]}')
58
+        ret.append(f'IBAN: {invoice.seller_bank_data["iban"]}')
49 59
 
50 60
     return '\n'.join(ret)
51 61
 
52 62
 
53
-def InvoiceTableToText(invoiceTable):
63
+def InvoiceTableToText(invoiceTable : InvoiceTable):
54 64
     ret = []
55 65
     if len(invoiceTable.vat) < 2:
56 66
         ret.append(u'Anz       Beschreibung                                  Preis     Gesamt')
... ...
@@ -111,7 +121,7 @@ def InvoiceTableToText(invoiceTable):
111 121
     return '\n'.join(ret)
112 122
 
113 123
 
114
-def InvoiceTextToText(invoiceText):
124
+def InvoiceTextToText(invoiceText : InvoiceText):
115 125
     ret = []
116 126
     for par in invoiceText.paragraphs:
117 127
         for s in split_to_width(par, 72):
118 128