40 from gncinvoicefkt
import *
41 except ImportError
as import_error:
42 print "Problem importing modules."
47 def __init__(self, msg):
57 filename_template =
None
58 filename_output =
None
65 opts, args = getopt.getopt(argv[1:],
"fhlI:t:o:", [
"help"])
66 except getopt.error, msg:
73 if opt[0]
in [
"-h",
"--help"]:
77 print "using invoice ID '" + str(invoice_id) +
"'."
79 filename_output = opt[1]
80 print "using output file", filename_output
82 filename_template = opt[1]
83 print "using template file", filename_template
86 print "listing invoices"
90 print "opts:",opts,
"args:",args
91 raise Usage(
"Only one input possible !")
93 raise Usage(
"No input given !")
97 if not filename_template:
100 raise Usage(
"No template given !")
103 if not filename_output:
104 if filename_template:
105 filename_output = filename_template +
".out"
106 print "no output filename given, will be:", filename_output
109 if err.msg ==
"Help:":
112 print >>sys.stderr,
"Error:",err.msg
113 print >>sys.stderr,
"for help use --help"
119 print "Invoke with",prog_name,
"gnucash_url."
120 print "where input is"
122 print "or file://filename"
123 print "or mysql://user:password@host/databasename"
125 print "-f force open = ignore lock"
126 print "-l list all invoices"
127 print "-h or --help for this help"
128 print "-I ID use invoice ID"
129 print "-t filename use filename as template file"
130 print "-o filename use filename as output file"
136 print "Opening", input_url,
"."
137 session = gnucash.Session(input_url, ignore_lock=ignore_lock)
138 except Exception
as exception:
139 print "Problem opening input."
144 root_account = book.get_root_account()
145 comm_table = book.get_table()
146 EUR = comm_table.lookup(
"CURRENCY",
"EUR")
148 invoice_list = get_all_invoices(book)
151 for number,invoice
in enumerate(invoice_list):
152 print str(number)+
")"
158 invoice = book.InvoiceLookupByID(invoice_id)
160 print "ID not found."
164 invoice = invoice_list[invoice_number]
166 print "Using the following invoice:"
169 loader = jinja2.FileSystemLoader(
'.')
170 env = jinja2.Environment(loader=loader)
171 template = env.get_template(filename_template)
175 output = template.render(invoice=invoice, locale=locale)
177 print "Writing output", filename_output,
"."
178 with open(filename_output,
'w')
as f:
179 f.write(output.encode(
'utf-8'))
181 if __name__ ==
"__main__":