2e99ffc45b6129f3af57b2534750a8ad82937b7a
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) 
8) def _breakLine(text, width=72):
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
21)   
22) 
Bernd Wurst Verstecke Bankdaten bei Rec...

Bernd Wurst authored 7 years ago

23) def InvoiceToText(iv, bankdata=True):
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

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')))
31) 
32)   ret.append('')
33)   for part in iv.parts:
Bernd Wurst Umbenannt aber wieder in ko...

Bernd Wurst authored 16 years ago

34)     if type(part) == Table:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

35)       ret.append(InvoiceTableToText(part))
Bernd Wurst Umbenannt aber wieder in ko...

Bernd Wurst authored 16 years ago

36)     elif type(part) == Text:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

37)       ret.append(InvoiceTextToText(part))
38)     else:
39)       raise NotImplementedError("Cannot handle part of type %s" % type(part))
40) 
41) 
Bernd Wurst Verstecke Bankdaten bei Rec...

Bernd Wurst authored 7 years ago

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

Bernd Wurst authored 16 years ago

48)   return ('\n'.join(ret)).encode('utf-8')
49) 
50) 
51) 
52) def InvoiceTableToText(invoiceTable):
53)   ret = []
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

54)   if len(invoiceTable.vat) < 2:
Bernd Wurst Einheit

Bernd Wurst authored 11 years ago

55)     ret.append(u'Anz       Beschreibung                                  Preis     Gesamt')
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

56)     ret.append(u'-'*72)
57)   else:
Bernd Wurst Einheit

Bernd Wurst authored 11 years ago

58)     ret.append(u'Anz       Beschreibung                                Preis       Gesamt')
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

59)     ret.append(u'-'*72)
60) 
61)   for el in invoiceTable.entries:
Bernd Wurst Einheit

Bernd Wurst authored 11 years ago

62)     unit = ''
63)     if el['unit']:
64)       unit = ' %s' % el['unit']
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

65)     if len(invoiceTable.vat) < 2:
Bernd Wurst Einheit

Bernd Wurst authored 11 years ago

66)       subject = _breakLine(el['subject'], width=39)
67)       ret.append(u'%5.2f %-3s %-39s  %10s %10s' % (el['count'], unit, subject[0], format_price(el['price']), format_price(el['total'])))
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

68)       for i in range(1,len(subject)):
Bernd Wurst Einheit

Bernd Wurst authored 11 years ago

69)         ret.append(u'          %s' % subject[i])
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

70)     else:
71)       subject = _breakLine(el['subject'], width=41)
Bernd Wurst Einheit

Bernd Wurst authored 11 years ago

72)       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'])))
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

73)       for i in range(1,len(subject)):
Bernd Wurst Einheit

Bernd Wurst authored 11 years ago

74)         ret.append(u'          %s' % subject[i])
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

75)     if 'desc' in el and el['desc']:
Bernd Wurst Einheit

Bernd Wurst authored 11 years ago

76)       desc = _breakLine(el['desc'], 39)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

77)       for line in desc:
Bernd Wurst Einheit

Bernd Wurst authored 11 years ago

78)         ret.append(u'          %s' % line)
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

79)   ret.append('-'*72)
80)   if invoiceTable.vatType == 'gross':
81)     ret.append((u'Rechnungsbetrag:  %11s' % format_price(invoiceTable.sum)).rjust(72))
82)     ret.append('')
83)     summaries = []
84)     if len(invoiceTable.vat) == 1:
85)       vat = invoiceTable.vat.keys()[0]
86)       summaries.append(u'      Im Rechnungsbetrag sind %.1f%% MwSt enthalten (%s)' % (vat*100, format_price((invoiceTable.sum/(vat+1))*vat)))
87)     else:
88)       for vat, vatdata in invoiceTable.vat.iteritems():
89)         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)))
90)     summaries.sort()
91)     for line in summaries:
92)       ret.append(line)
93)   else:
94)     ret.append((u'Nettobetrag: %11s' % format_price(invoiceTable.sum)).rjust(72))
95)     summaries = []
96)     if len(invoiceTable.vat) == 1:
97)       vat = invoiceTable.vat.keys()[0]
98)       summaries.append((u'zzgl. %.1f%% MwSt: %11s' % (vat*100, format_price(vat*invoiceTable.sum))).rjust(72))
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

99)     elif len(invoiceTable.vat) > 1:
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

100)       for vat, vatdata in invoiceTable.vat.iteritems():
101)         summaries.append((u'zzgl. %4.1f%% MwSt (%s): %11s' % (vat*100, vatdata[1], format_price(vat*vatdata[0]))).rjust(72))
102)     summaries.sort()
103)     for line in summaries:
104)       ret.append(line)
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

105)     sum = invoiceTable.sum
Bernd Wurst Struktur verändern (broken!)

Bernd Wurst authored 16 years ago

106)     for vat, vatdata in invoiceTable.vat.iteritems():
Bernd Wurst Innergemeinschaftliche Leis...

Bernd Wurst authored 12 years ago

107)       sum += vat*vatdata[0]