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
text.py
Struktur verändern (broken!)
Bernd Wurst
commited
6dc3771
at 2008-01-23 17:59:01
text.py
Blame
History
Raw
# -* coding: utf8 *- from InvoiceObjects import * from utils import format_price, split_to_width def _breakLine(text, width=72): lines = [] paras = text.split('\n') for para in paras: words = para.split(' ') while len(words) > 0: mywords = [words[0], ] del words[0] while len(words) > 0 and len(u' '.join(mywords) + ' ' + words[0]) <= width: mywords.append(words[0]) del words[0] lines.append(' '.join(mywords)) return lines def InvoiceToText(iv): ret = [] ret.append(u'Rechnungsempfänger:') for line in iv.addresslines: ret.append(' %s' % line) ret.append('') ret.append('Kundennummer: %4i' % iv.customerno) ret.append('Rechnungsnummer: %4i Rechnungsdatum: %s' % (iv.id, iv.date.strftime('%d.%m.%Y'))) ret.append('') for part in iv.parts: if type(part) == InvoiceTable: ret.append(InvoiceTableToText(part)) elif type(part) == InvoiceText: ret.append(InvoiceTextToText(part)) else: raise NotImplementedError("Cannot handle part of type %s" % type(part)) ret.append('-'*72) ret.append('Unsere Bankverbindung:') ret.append('Volksbank Backnang, BLZ 602 911 20, Konto-Nr. 671279 017') ret.append('IBAN: DE78602911200671279017, BIC: GENODES1VBK') return ('\n'.join(ret)).encode('utf-8') def InvoiceTableToText(invoiceTable): ret = [] if len(invoiceTable.vat) == 1: ret.append(u'Anz Beschreibung Preis Gesamt') ret.append(u'-'*72) else: ret.append(u'Anz Beschreibung Preis Gesamt') ret.append(u'-'*72) for el in invoiceTable.entries: if len(invoiceTable.vat) == 1: subject = _breakLine(el['subject'], width=43) ret.append(u'%5.2f %-43s %10s %10s' % (el['count'], subject[0], format_price(el['price']), format_price(el['total']))) for i in range(1,len(subject)): ret.append(u' %s' % subject[i]) else: subject = _breakLine(el['subject'], width=41) ret.append(u'%5.2f %-41s %10s %s %10s' % (el['count'], subject[0], format_price(el['price']), invoiceTable.vat[el['vat']][1], format_price(el['total']))) for i in range(1,len(subject)): ret.append(u' %s' % subject[i]) if 'desc' in el and el['desc']: desc = _breakLine(el['desc'], 43) for line in desc: ret.append(u' %s' % line) ret.append('-'*72) if invoiceTable.vatType == 'gross': ret.append((u'Rechnungsbetrag: %11s' % format_price(invoiceTable.sum)).rjust(72)) ret.append('') summaries = [] if len(invoiceTable.vat) == 1: vat = invoiceTable.vat.keys()[0] summaries.append(u' Im Rechnungsbetrag sind %.1f%% MwSt enthalten (%s)' % (vat*100, format_price((invoiceTable.sum/(vat+1))*vat))) else: for vat, vatdata in invoiceTable.vat.iteritems(): summaries.append(u' %s: Im Teilbetrag von %s sind %.1f%% MwSt enthalten (%s)' % (vatdata[1], format_price(vatdata[0]), vat*100, format_price((vatdata[0]/(vat+1))*vat))) summaries.sort() for line in summaries: ret.append(line) else: ret.append((u'Nettobetrag: %11s' % format_price(invoiceTable.sum)).rjust(72)) summaries = [] if len(invoiceTable.vat) == 1: vat = invoiceTable.vat.keys()[0] summaries.append((u'zzgl. %.1f%% MwSt: %11s' % (vat*100, format_price(vat*invoiceTable.sum))).rjust(72)) else: for vat, vatdata in invoiceTable.vat.iteritems(): summaries.append((u'zzgl. %4.1f%% MwSt (%s): %11s' % (vat*100, vatdata[1], format_price(vat*vatdata[0]))).rjust(72)) summaries.sort() for line in summaries: ret.append(line) sum = 0 for vat, vatdata in invoiceTable.vat.iteritems(): sum += (vat+1)*vatdata[0] ret.append((u'Rechnungsbetrag: %11s' % format_price(sum)).rjust(72)) ret.append('') return ('\n'.join(ret)).encode('utf-8') def InvoiceTextToText(invoiceText): ret = [] for par in invoiceText.paragraphs: for str in split_to_width(par, 72): ret.append(str) ret.append('') return ('\n'.join(ret)).encode('utf-8')