b9907381f5b410ff1c46062564fcce6340289ce3
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

1) # -* coding: utf8 *-
2) 
3) import datetime
4) 
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

5) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

6) class InvoiceImage(object):
7)     def __init__(self, pilimage, caption=None, dpi=80, alignment="left"):
8)         self.imagedata = pilimage
9)         self.alignment = alignment
10)         self.dpi = dpi
11)         self.caption = caption
12) 
13) 
14) class InvoiceText(object):
15)     def __init__(self, content, urgent=False, headline=None):
16)         self.paragraphs = [content]
17)         self.urgent = urgent
18)         self.headline = headline
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

19)         self.fontsize = 0  # relative Schriftgröße ggü default
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

20) 
21)     def addParagraph(self, content):
22)         self.paragraphs.append(content)
23) 
24) 
25) class InvoiceTable(object):
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

26)     def __init__(self, vatType='gross', tender=False, summary=True):
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

27)         self.entries = []
28)         self.vat = {}
29)         self.sum = 0.0
30)         self.payments = []
31)         self.tender = tender
32)         self.summary = summary
33)         if vatType not in ['gross', 'net']:
34)             raise ValueError('vatType must be »gross« or »net«')
35)         self.vatType = vatType
36)     
37)     def validEntry(self, entry):
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

38)         """bekommt einen Eintrag und liefert einen Eintrag, wenn ok; wirft ansonsten ValueError.
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

39)         wird benutzt um z.B. die Summe auszurechnen oder ähnliches
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

40)         """
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

41)         k = entry.keys()
42)         e = entry
43)         if not ('count' in k and 'unit' in k and 'subject' in k and 'price' in k and 'vat' in k):
44)             raise ValueError('Some data is missing!')
45)         ret = {'type': 'entry',
46)                'count': e['count'],
47)                'unit': e['unit'],
48)                'subject': e['subject'],
49)                'price': e['price'],
50)                'total': (e['price'] * e['count']),
51)                'vat': e['vat'],
52)                'tender': False,
53)                }
54)         if ret['vat'] > 1:
55)             ret['vat'] = float(ret['vat']) / 100
56)             
57)         if 'tender' in e.keys():
58)             ret['tender'] = e['tender']
59)         if 'desc' in k:
60)             ret['desc'] = e['desc']
61)         if 'period_start' in k:
62)             ret['period_start'] = e['period_start']
63)         if 'period_end' in k:
64)             ret['period_end'] = e['period_end']
65) 
66)         return ret
67)     
68)     def addItem(self, data):
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

69)         """Fügt eine Zeile ein. data muss ein Dict mit passenden Keys und passenden
70)         Typen sein"""
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

71)         d = self.validEntry(data)
72)         if not d['vat'] in self.vat.keys():
73)             self.vat[d['vat']] = [0, chr(65+len(self.vat))]
74)         if 'tender' not in data or not data['tender']:
75)             self.vat[d['vat']][0] += d['total']
76)             self.sum += d['total']
77)         self.entries.append(d)
78)     
79)     def addTitle(self, title):
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

80)         self.entries.append({'type': 'title', 'title': title, })
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

81) 
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

82)     def addPayment(self, payment_type, amount, date):
83)         self.payments.append({"type": payment_type, "amount": amount, "date": date})
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

84) 
85) 
86) RECHNUNG = 380
87) ANGEBOT = 1
88) GUTSCHRIFT = 381
89) KORREKTUR = 384
90) 
91) VAT_REGULAR = 'S'
92) VAT_KLEINUNTERNEHMER = 'E'
93) VAT_INNERGEM = 'K'
94) 
Bernd Wurst WiP

Bernd Wurst authored 4 months ago

95) PAYMENT_LASTSCHRIFT = "59"
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

96) PAYMENT_UEBERWEISUNG = "58"
Bernd Wurst WiP

Bernd Wurst authored 4 months ago

97) PAYMENT_BANKKONTO = "42"
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

98) PAYMENT_ONLINE = "68"
Bernd Wurst WiP

Bernd Wurst authored 4 months ago

99) PAYMENT_BAR = "10"
100) PAYMENT_KARTE = "48"
101) 
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

102) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

103) class Invoice(object):
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

104)     def __init__(self, tender=False):
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

105)         self.customerno = None
106)         self.customer = {
107)             "id": None,
108)             "name": None,
109)             "address": {
110)                 "postcode": None,
111)                 "city_name": None,
112)                 "line1": None,
113)                 "line2": None,
114)                 "line3": None,
115)                 "country_id": None,
116)             },
Bernd Wurst Telefonnummer

Bernd Wurst authored 4 months ago

117)             "phone": None,
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

118)             "email": None,
119)         }
120)         self.buyer = self.customer
121)         self.seller = {
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

122)             "name": None,  # juristischer Name
123)             "trade_name": None,  # Firmenname
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

124)             "address": {
125)                 "postcode": None,
126)                 "city_name": None,
127)                 "line1": None,
128)                 "line2": None,
129)                 "line3": None,
130)                 "country_id": None,
131)             },
132)             "phone": None,
133)             "email": None,
134)             "website": None,
135)         }
136)         self.seller_vat_id = None
137)         self.seller_bank_data = {
138)             'kontoinhaber': None,
139)             'iban': None,
140)             'bic': None,
141)             'bankname': None,
142)         }
143)         self.due_date = None
144)         self.debit = False
Bernd Wurst WiP

Bernd Wurst authored 4 months ago

145)         self.payment_type = PAYMENT_UEBERWEISUNG
Bernd Wurst Referenznummern auf allen A...

Bernd Wurst authored 4 months ago

146)         self.leitweg_id = None
Bernd Wurst Telefonnummer

Bernd Wurst authored 4 months ago

147)         self.buyer_reference = None
148)         self.order_number = None
Bernd Wurst Referenznummern auf allen A...

Bernd Wurst authored 4 months ago

149)         self.contract_number = None
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

150)         self.debit_mandate_id = None
151)         self.creditor_reference_id = None
152)         self.buyer_bank_data = {
153)             'kontoinhaber': None,
154)             'iban': None,
155)             'bic': None,
156)             'bankname': None,
157)         }
158)         self.vat_type = VAT_REGULAR
159)         self.salutation = 'Sehr geehte Damen und Herren,'
160)         self.id = None
161)         self.cash = True
162)         self.type = RECHNUNG
163)         self.logo_image_file = None
164)         self.tender = tender
165)         self.title = 'Rechnung'
166)         if tender:
167)             self.title = 'Angebot'
168)         self.official = True
169)         self.parts = []
170)         self.pagecount = 0
171)         self.date = datetime.date.today()
172)     
173)     def setDate(self, date):
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

174)         if not isinstance(date, datetime.date):