Exports an invoice to lco-file for use with LaTeX, see Python invoice export.
More...
Go to the source code of this file.
Exports an invoice to lco-file for use with LaTeX, see Python invoice export.
- Author
- Christoph Holtermann (c.holtermann (at) gmx.de)
- Date
- May 2011
The output file can be imported into KOMA-Script-letters. This works primarily for germany. Internationalization welcome!
Additional files:
- Invoice.tex
Example template file. Should be modified according to personal needs.
- rechnung.sty
style file for invoices.
This file is not part of the python-bindings!
For an example where to get it see section credits below.
Usage :
latex_invoice -l -f -n INVOICE_NUMBER file://testfile
will create file data.lco.
latex --output-format=pdf Invoice.tex
should run latex on file Invoice.tex and result in Invoice.pdf. Invoice.tex includes data.lco.
Additional information :
Credits to and ideas from
To Do:
- get own contact data from gnucash
- have own bank information in footline
- nicer formatting of invoice date and date due
- is there anything else missing in this invoice ?
Definition in file latex_invoices.py.
◆ invoice_to_lco()
def latex_invoices.invoice_to_lco |
( |
|
invoice | ) |
|
returns a string which forms a lco-file for use with LaTeX
Definition at line 91 of file latex_invoices.py.
91 def invoice_to_lco(invoice):
92 """returns a string which forms a lco-file for use with LaTeX""" 94 lco_out =
u"\ProvidesFile{data.lco}[]\n" 96 def write_variable(ukey, uvalue, replace_linebreak=True):
99 if uvalue.endswith(
"\n"):
100 uvalue = uvalue[0 : len(uvalue) - 1]
102 if not ukey
in [
u"fromaddress",
u"toaddress",
u"date"]:
103 outstr +=
u"\\newkomavar{" 107 outstr +=
u"\\setkomavar{" 110 if replace_linebreak:
111 outstr += uvalue.replace(
u"\n",
u"\\\\") +
"}" 116 owner = invoice.GetOwner()
117 if owner.GetName() !=
"":
118 add_str += owner.GetName() +
"\n" 120 addr = owner.GetAddr()
121 if addr.GetName() !=
"":
122 add_str += addr.GetName() +
"\n" 123 if addr.GetAddr1() !=
"":
124 add_str += addr.GetAddr1() +
"\n" 125 if addr.GetAddr2() !=
"":
126 add_str += addr.GetAddr2() +
"\n" 127 if addr.GetAddr3() !=
"":
128 add_str += addr.GetAddr3() +
"\n" 129 if addr.GetAddr4() !=
"":
130 add_str += addr.GetAddr4() +
"\n" 132 lco_out += write_variable(
"toaddress2", add_str)
135 inr_str = invoice.GetID()
136 lco_out += write_variable(
"rechnungsnummer", inr_str)
139 date = invoice.GetDatePosted()
140 udate = date.strftime(
"%d.%m.%Y")
141 lco_out += write_variable(
"date", udate) +
"\n" 144 date_due = invoice.GetDateDue()
145 udate_due = date_due.strftime(
"%d.%m.%Y")
146 lco_out += write_variable(
"date_due", udate_due) +
"\n" 150 locale.setlocale(locale.LC_ALL,
"")
151 for n, ent
in enumerate(invoice.GetEntries()):
155 if type(ent) != Entry:
156 ent = Entry(instance=ent)
158 descr = ent.GetDescription()
159 price = ent.GetInvPrice().to_double()
160 n = ent.GetQuantity()
162 uprice = locale.currency(price).rstrip(
" EUR")
164 int(float(n.num()) / n.denom())
167 line_str =
u"\Artikel{" 178 lco_out += write_variable(
"entries", ent_str)