git.schokokeks.org
Repositories
Help
Report an Issue
invoice.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
01557cd
Branches
Tags
factur-x_localdata
master
invoice.git
src
rechnung
Invoice
__init__.py
Typo
Bernd Wurst
commited
01557cd
at 2010-10-12 09:19:22
__init__.py
Blame
History
Raw
# -* coding: utf8 *- import datetime class Text(object): def __init__(self, content, urgent=False, headline=None): self.paragraphs = [content] self.urgent = urgent self.headline = headline def addParagraph(self, content): self.paragraphs.append(content) class Table(object): def __init__(self, vatType = 'gross', tender = False, summary = True): self.entries = [] self.vat = {} self.sum = 0.0 self.tender = tender self.summary = summary if vatType not in ['gross', 'net']: raise ValueError('vatType must be »gross« or »net«') self.vatType = vatType def validEntry(self, entry): '''bekommt einen Eintrag und liefert einen Eintrag wenn ok, wirft ansonsten ValueError. wird benutzt um z.B. die Summe auszurechnen oder ähnliches ''' k = entry.keys() e = entry if not ('count' in k and 'subject' in k and 'price' in k and 'vat' in k): raise ValueError('Some data is missing!') ret = {'count': e['count'], 'subject': e['subject'], 'price': e['price'], 'total': (e['price'] * e['count']), 'vat': e['vat'], 'tender': False, } if 'tender' in e.keys(): ret['tender'] = e['tender'] if 'desc' in k: ret['desc'] = e['desc'] return ret def addItem(self, data): '''Fügt eine Zeile ein. data muss ein Dict mit passenden Keys und passenden Typen sein''' d = self.validEntry(data) if not d['vat'] in self.vat.keys(): self.vat[d['vat']] = [0, chr(65+len(self.vat))] if 'tender' not in data or not data['tender']: self.vat[d['vat']][0] += d['total'] self.sum += d['total'] self.entries.append(d) class Invoice(object): tender = False caption = 'Rechnung' def __init__(self): self.customerno = None self.addresslines = ['', ] self.salutation = 'Sehr geehrte Damen und Herren,' self.id = None self.parts = [] self.pagecount = 0 self.date = datetime.date.today() def setDate(self, date): if type(date) != datetime.date: raise ValueError('date must be of type »datetime.date«') self.date = date class Tender(Invoice): tender = True caption = 'Angebot' class Generic(Invoice): tender = False caption = ''