32416ff37d053b7cc0527c4f8ba9d0b9ab96400a
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

1) # -* coding: utf8 *-
2) 
Bernd Wurst Python-3-Migration

Bernd Wurst authored 5 years ago

3) from __future__ import division
Bernd Wurst Umbenannt aber wieder in ko...

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 5 years ago

23) def InvoiceToText(iv, bankdata=True):
24)     ret = []
25)     ret.append(u'Rechnungsempfänger:')
26)     for line in iv.addresslines:
27)         ret.append('  %s' % line)
28)     ret.append('')
29)     ret.append('Kundennummer:    %4i' % iv.customerno)
30)     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

31) 
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 7 years ago

40) 
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 16 years ago

46) 
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 12 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 5 years ago

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

Bernd Wurst authored 5 years ago

86)             for vat, vatdata in list(invoiceTable.vat.items()):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

87)                 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)))
88)         summaries.sort()
89)         for line in summaries:
90)             ret.append(line)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

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

Bernd Wurst authored 5 years ago

92)         ret.append((u'Nettobetrag: %11s' % format_price(invoiceTable.sum)).rjust(72))
93)         summaries = []
94)         if len(invoiceTable.vat) == 1:
95)             vat = list(invoiceTable.vat.keys())[0]
96)             summaries.append((u'zzgl. %.1f%% MwSt: %11s' % (vat * 100, format_price(vat * invoiceTable.sum))).rjust(72))
97)         elif len(invoiceTable.vat) > 1:
Bernd Wurst Python-3-Migration

Bernd Wurst authored 5 years ago

98)             for vat, vatdata in list(invoiceTable.vat.items()):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

99)                 summaries.append((u'zzgl. %4.1f%% MwSt (%s): %11s' % (vat * 100, vatdata[1], format_price(vat * vatdata[0]))).rjust(72))
100)         summaries.sort()
101)         for line in summaries:
102)             ret.append(line)
103)         sum = invoiceTable.sum
Bernd Wurst Python-3-Migration

Bernd Wurst authored 5 years ago

104)         for vat, vatdata in list(invoiceTable.vat.items()):
Bernd Wurst automatische code-style-fixes

Bernd Wurst authored 5 years ago

105)             sum += vat * vatdata[0]
106)         ret.append((u'Rechnungsbetrag: %11s' % format_price(sum)).rjust(72))
107)     ret.append('')
108)     return ('\n'.join(ret)).encode('utf-8')
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

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