GnuCash  4.11-137-g155922540d+
Data Structures | Functions
latex_invoices.py File Reference

Exports an invoice to lco-file for use with LaTeX, see Python invoice export. More...

Go to the source code of this file.

Data Structures

class  latex_invoices.Usage
 

Functions

def latex_invoices.invoice_to_lco (invoice)
 
def latex_invoices.main (argv=None)
 

Detailed Description

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:

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:

Definition in file latex_invoices.py.

Function Documentation

◆ 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"""
93 
94  lco_out = u"\ProvidesFile{data.lco}[]\n"
95 
96  def write_variable(ukey, uvalue, replace_linebreak=True):
97 
98  outstr = u""
99  if uvalue.endswith("\n"):
100  uvalue = uvalue[0 : len(uvalue) - 1]
101 
102  if not ukey in [u"fromaddress", u"toaddress", u"date"]:
103  outstr += u"\\newkomavar{"
104  outstr += ukey
105  outstr += u"}\n"
106 
107  outstr += u"\\setkomavar{"
108  outstr += ukey
109  outstr += u"}{"
110  if replace_linebreak:
111  outstr += uvalue.replace(u"\n", u"\\\\") + "}"
112  return outstr
113 
114  # Write owners address
115  add_str = u""
116  owner = invoice.GetOwner()
117  if owner.GetName() != "":
118  add_str += owner.GetName() + "\n"
119 
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"
131 
132  lco_out += write_variable("toaddress2", add_str)
133 
134  # Invoice number
135  inr_str = invoice.GetID()
136  lco_out += write_variable("rechnungsnummer", inr_str)
137 
138  # date
139  date = invoice.GetDatePosted()
140  udate = date.strftime("%d.%m.%Y")
141  lco_out += write_variable("date", udate) + "\n"
142 
143  # date due
144  date_due = invoice.GetDateDue()
145  udate_due = date_due.strftime("%d.%m.%Y")
146  lco_out += write_variable("date_due", udate_due) + "\n"
147 
148  # Write the entries
149  ent_str = u""
150  locale.setlocale(locale.LC_ALL, "")
151  for n, ent in enumerate(invoice.GetEntries()):
152 
153  line_str = u""
154 
155  if type(ent) != Entry:
156  ent = Entry(instance=ent) # Add to method_returns_list
157 
158  descr = ent.GetDescription()
159  price = ent.GetInvPrice().to_double()
160  n = ent.GetQuantity()
161 
162  uprice = locale.currency(price).rstrip(" EUR")
163  un = str(
164  int(float(n.num()) / n.denom())
165  ) # choose best way to format numbers according to locale
166 
167  line_str = u"\Artikel{"
168  line_str += un
169  line_str += u"}{"
170  line_str += descr
171  line_str += u"}{"
172  line_str += uprice
173  line_str += u"}"
174 
175  # print(line_str)
176  ent_str += line_str
177 
178  lco_out += write_variable("entries", ent_str)
179 
180  return lco_out
181 
182