diff options
Diffstat (limited to 'fracture/__main__.py')
-rw-r--r-- | fracture/__main__.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/fracture/__main__.py b/fracture/__main__.py index ee26bbe..c99b0e9 100644 --- a/fracture/__main__.py +++ b/fracture/__main__.py @@ -1,5 +1,6 @@ from invoice import Invoice, Tax, Product, Conf import db +from jinja2 import Template from csv import DictWriter import datetime @@ -139,11 +140,19 @@ def summarize(xlsx=False, year=None, quarter=None): wrtr.writerow(r) @command -def render(id, type=None): - invoice = Invoice.load_by_idrepr(id, type) - if invoice is not None: +def render(id, type=None, format=None): + invoice = Invoice.load(id, type) + if format == "json": print(invoice.to_json()) + if format == "xelatex": + # TODO AUTOMATE TEMPLATE SEARCH AND THAT, THIS IS THIS FOR DEV + with open("templates/template.tex", "r") as f: + template_text = f.read() + template = Template(template_text) + if invoice is not None: + print(template.render(invoice=invoice.to_dict())) + if __name__ == "__main__": load_config() @@ -181,6 +190,8 @@ if __name__ == "__main__": help="Invoice identification string") summary_parser.add_argument("--type", type=str, help="Invoice type", default="sent") + summary_parser.add_argument("--format", type=str, + choices={"json", "xelatex"}, help="Invoice type", default="json") summary_parser.set_defaults(func=render) |