b37b226ec14c729c9b10ed6239d9dc085b0b3680
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 Einheiten soweit möglich al...

Bernd Wurst authored 2 months ago

103) UNITS = {
104)     # key = XML-Code, value = (Langform Einzahl, Langform Mehrzahl, Kurzform, [mögliche weitere Schreibweisen,...])
105)     'H87': ('Stück', 'Stück', 'Stk', 'pcs'),
106)     'SEC': ('Sekunde', 'Sekunden', 's', 'Sek.', 'Sek'),
107)     'MIN': ('Minute', 'Minuten', 'min', 'Min.', 'Min'),
108)     'HUR': ('Stunde', 'Stunden', 'h', 'Std.', 'Std'),
109)     'DAY': ('Tag', 'Tage', 'Tg', 'd'),
110)     'WEE': ('Woche', 'Wochen', 'Woch.', 'Woch'),
111)     'MON': ('Monat', 'Monate', 'Mon.', 'Mon'),
112)     'ANN': ('Jahr', 'Jahre', 'J.', 'y'),
113)     'LTR': ('Liter', 'Liter', 'l', 'Ltr'),
114)     'MTQ': ('Kubikmeter', 'Kubikmeter', 'm³', 'cbm'),
115)     'GRM': ('Gramm', 'Gramm', 'g', 'Gr', 'gr'),
116)     'KGM': ('Kilogramm', 'Kilogramm', 'kg', 'Kilo'),
117)     'TNE': ('Tonne', 'Tonnen', 't'),
118)     'DTN': ('Dezitonne', 'Dezitonnen', 'dt'),
119)     'MTR': ('Meter', 'Meter', 'm', 'Mtr'),
120)     'MMT': ('Millimeter', 'Millimeter', 'mm'),
121)     'KMT': ('Kilometer', 'Kilometer', 'km'),
122)     'MTK': ('Quadratmeter', 'Quadratmeter', 'm²', 'qm'),
123)     'KWT': ('Kilowatt', 'Kilowatt', 'kW'),
124)     'MAW': ('Megawatt', 'Megawatt', 'MW'),
125)     'KWH': ('Kilowattstunde', 'Kilowattstunden', 'kWh'),
126)     'MWH': ('Megawattstunde', 'Megawattstunden', 'MWh'),
127)     'D97': ('Palette', 'Paletten', 'Pal'),
128)     'AD':  ('Byte', 'Bytes', 'Byte', 'octet', 'octets'),
129)     '2P':  ('Kilobyte', 'Kilobytes', 'KB'),
130)     '4L':  ('Megabyte', 'Megabytes', 'MB'),
131)     'E34': ('Gigabyte', 'Gigabytes', 'GB'),
132)     'E35': ('Terabyte', 'Terabytes', 'TB'),
133)     'E36': ('Petabyte', 'Petabytes', 'PB'),
134)     '1I': ('Pauschal', 'Pauschale', 'Psch.', 'Psch'),
135) }
136) 
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

137) 
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

140)         self.customerno = None
141)         self.customer = {
142)             "id": None,
143)             "name": None,
144)             "address": {
145)                 "postcode": None,
146)                 "city_name": None,
147)                 "line1": None,
148)                 "line2": None,
149)                 "line3": None,
150)                 "country_id": None,
151)             },
Bernd Wurst Telefonnummer

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

153)             "email": None,
154)         }
155)         self.buyer = self.customer
156)         self.seller = {
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

159)             "address": {
160)                 "postcode": None,
161)                 "city_name": None,
162)                 "line1": None,
163)                 "line2": None,
164)                 "line3": None,
165)                 "country_id": None,
166)             },
167)             "phone": None,
168)             "email": None,
169)             "website": None,
170)         }
171)         self.seller_vat_id = None
172)         self.seller_bank_data = {
173)             'kontoinhaber': None,
174)             'iban': None,
175)             'bic': None,
176)             'bankname': None,
177)         }
178)         self.due_date = None
179)         self.debit = False
Bernd Wurst WiP

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

181)         self.leitweg_id = None
Bernd Wurst Telefonnummer

Bernd Wurst authored 4 months ago

182)         self.buyer_reference = None
183)         self.order_number = None
Bernd Wurst Referenznummern auf allen A...

Bernd Wurst authored 4 months ago

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

Bernd Wurst authored 4 months ago

185)         self.debit_mandate_id = None
186)         self.creditor_reference_id = None
187)         self.buyer_bank_data = {
188)             'kontoinhaber': None,
189)             'iban': None,
190)             'bic': None,
191)             'bankname': None,
192)         }
193)         self.vat_type = VAT_REGULAR
Bernd Wurst Typo

Bernd Wurst authored 3 months ago

194)         self.salutation = 'Sehr geehrte Damen und Herren,'
Bernd Wurst In eigenes GIT ausgelagert

Bernd Wurst authored 4 months ago

195)         self.id = None
196)         self.cash = True
197)         self.type = RECHNUNG
198)         self.logo_image_file = None
199)         self.tender = tender
200)         self.title = 'Rechnung'
201)         if tender:
202)             self.title = 'Angebot'
203)         self.official = True
204)         self.parts = []
205)         self.pagecount = 0
206)         self.date = datetime.date.today()
207)     
208)     def setDate(self, date):
Bernd Wurst Codestyle-Fixes

Bernd Wurst authored 4 months ago

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