a400ea58b89079bb5373a5677137269d86df16b0
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):
Bernd Wurst new feature: indentation fo...

Bernd Wurst authored 4 months ago

15)     def __init__(self, content, urgent=False, headline=None, indent=None):
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

16)         self.paragraphs = [content]
17)         self.urgent = urgent
18)         self.headline = headline
Bernd Wurst new feature: indentation fo...

Bernd Wurst authored 4 months ago

19)         self.indent = indent
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

41)         """
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

82) 
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

97) PAYMENT_UEBERWEISUNG = "58"
Bernd Wurst WiP

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

99) PAYMENT_ONLINE = "68"
Bernd Wurst WiP

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

103) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

147)         self.leitweg_id = None
Bernd Wurst Telefonnummer

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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