8f583de0e69086e8e6c411fa7906a943362f8790
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

1) # -* coding: utf8 *-
2) 
Bernd Wurst Umbenannt aber wieder in ko...

Bernd Wurst authored 16 years ago

3) from Invoice import Text, Table
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

4) from utils import format_price, split_to_width
5) 
6) 
7) def _breakLine(text, width=72):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

8)     lines = []
9)     paras = text.split('\n')
10)     for para in paras:
11)         words = para.split(' ')
12)         while len(words) > 0:
13)             mywords = [words[0], ]
14)             del words[0]
15)             while len(words) > 0 and len(u' '.join(mywords) + ' ' + words[0]) <= width:
16)                 mywords.append(words[0])
17)                 del words[0]
18)             lines.append(' '.join(mywords))
19)     return lines
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

20) 
21) 
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

22) def InvoiceToText(iv, bankdata=True):
23)     ret = []
24)     ret.append(u'Rechnungsempfänger:')
25)     for line in iv.addresslines:
26)         ret.append('  %s' % line)
27)     ret.append('')
28)     ret.append('Kundennummer:    %4i' % iv.customerno)
29)     ret.append('Rechnungsnummer: %4i    Rechnungsdatum:  %s' % (iv.id, iv.date.strftime('%d.%m.%Y')))
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

30) 
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

31)     ret.append('')
32)     for part in iv.parts:
33)         if type(part) == Table:
34)             ret.append(InvoiceTableToText(part))
35)         elif type(part) == Text:
36)             ret.append(InvoiceTextToText(part))
37)         else:
38)             raise NotImplementedError("Cannot handle part of type %s" % type(part))
Bernd Wurst Verstecke Bankdaten bei Rec...

Bernd Wurst authored 7 years ago

39) 
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

40)     if bankdata:
41)         ret.append('-' * 72)
42)         ret.append('Unsere Bankverbindung:')
43)         ret.append('Volksbank Backnang, BLZ 602 911 20, Konto-Nr. 41512 006')
44)         ret.append('IBAN: DE91602911200041512006, BIC: GENODES1VBK')
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

45) 
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

46)     return ('\n'.join(ret)).encode('utf-8')
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

47) 
48) 
49) def InvoiceTableToText(invoiceTable):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

50)     ret = []
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

51)     if len(invoiceTable.vat) < 2:
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

52)         ret.append(u'Anz       Beschreibung                                  Preis     Gesamt')
53)         ret.append(u'-' * 72)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

54)     else:
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

55)         ret.append(u'Anz       Beschreibung                                Preis       Gesamt')
56)         ret.append(u'-' * 72)
57) 
58)     for el in invoiceTable.entries:
59)         unit = ''
60)         if el['unit']:
61)             unit = ' %s' % el['unit']
62)         if len(invoiceTable.vat) < 2:
63)             subject = _breakLine(el['subject'], width=39)
64)             ret.append(u'%5.2f %-3s %-39s  %10s %10s' % (el['count'], unit, subject[0], format_price(el['price']), format_price(el['total'])))
65)             for i in range(1, len(subject)):
66)                 ret.append(u'          %s' % subject[i])
67)         else:
68)             subject = _breakLine(el['subject'], width=41)
69)             ret.append(u'%5.2f %-3s %-37s  %10s %s %10s' % (el['count'], unit, subject[0], format_price(el['price']), invoiceTable.vat[el['vat']][1], format_price(el['total'])))
70)             for i in range(1, len(subject)):
71)                 ret.append(u'          %s' % subject[i])
72)         if 'desc' in el and el['desc']:
73)             desc = _breakLine(el['desc'], 39)
74)             for line in desc:
75)                 ret.append(u'          %s' % line)
76)     ret.append('-' * 72)
77)     if invoiceTable.vatType == 'gross':
78)         ret.append((u'Rechnungsbetrag:  %11s' % format_price(invoiceTable.sum)).rjust(72))
79)         ret.append('')
80)         summaries = []
81)         if len(invoiceTable.vat) == 1:
82)             vat = list(invoiceTable.vat.keys())[0]
83)             summaries.append(u'      Im Rechnungsbetrag sind %.1f%% MwSt enthalten (%s)' % (vat * 100, format_price((invoiceTable.sum / (vat + 1)) * vat)))
84)         else:
85)             for vat, vatdata in invoiceTable.vat.items():
86)                 summaries.append(u'    %s: Im Teilbetrag von %s sind %.1f%% MwSt enthalten (%s)' % (vatdata[1], format_price(vatdata[0]), vat * 100, format_price((vatdata[0] / (vat + 1)) * vat)))
87)         summaries.sort()
88)         for line in summaries:
89)             ret.append(line)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

90)     else:
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

91)         ret.append((u'Nettobetrag: %11s' % format_price(invoiceTable.sum)).rjust(72))
92)         summaries = []
93)         if len(invoiceTable.vat) == 1:
94)             vat = list(invoiceTable.vat.keys())[0]
95)             summaries.append((u'zzgl. %.1f%% MwSt: %11s' % (vat * 100, format_price(vat * invoiceTable.sum))).rjust(72))
96)         elif len(invoiceTable.vat) > 1:
97)             for vat, vatdata in invoiceTable.vat.items():
98)                 summaries.append((u'zzgl. %4.1f%% MwSt (%s): %11s' % (vat * 100, vatdata[1], format_price(vat * vatdata[0]))).rjust(72))
99)         summaries.sort()
100)         for line in summaries:
101)             ret.append(line)
102)         sum = invoiceTable.sum
103)         for vat, vatdata in invoiceTable.vat.items():
104)             sum += vat * vatdata[0]
105)         ret.append((u'Rechnungsbetrag: %11s' % format_price(sum)).rjust(72))
106)     ret.append('')
107)     return ('\n'.join(ret)).encode('utf-8')
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

108) 
109) 
110) def InvoiceTextToText(invoiceText):