git.schokokeks.org
Repositories
Help
Report an Issue
invoice.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
6dc3771
Branches
Tags
factur-x_localdata
master
invoice.git
src
rechnung
Invoice
InvoiceObjects.py
Struktur verändern (broken!)
Bernd Wurst
commited
6dc3771
at 2008-01-23 17:59:01
InvoiceObjects.py
Blame
History
Raw
# -* coding: utf8 *- import datetime class InvoiceText(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 InvoiceTable(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): def __init__(self, tender = False): self.customerno = None self.addresslines = ['', ] self.salutation = 'Sehr geehte Damen und Herren,' self.id = None self.tender = tender 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