diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2020-08-06 12:43:58 +0200 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2020-08-06 12:43:58 +0200 |
commit | e74fb23d68d94150d8ee18c8e553307cb07ec6b6 (patch) | |
tree | d343aa02c66adab875b4d92a2679396d527a4b41 /fracture/__main__.py | |
parent | c901bfa8e7a6f33ef7cb369995510e83cd31e52d (diff) |
Return the summary with the different VAT+Taxes in order
Diffstat (limited to 'fracture/__main__.py')
-rw-r--r-- | fracture/__main__.py | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/fracture/__main__.py b/fracture/__main__.py index d0305ab..c51c556 100644 --- a/fracture/__main__.py +++ b/fracture/__main__.py @@ -1,6 +1,7 @@ -from invoice import Invoice, Tax +from invoice import Invoice, Tax, Product import db +from csv import DictWriter import datetime from functools import wraps from argparse import ArgumentParser as ap @@ -27,6 +28,10 @@ def load_config(): conf = ConfigParser() conf.read(confile) + # VAT-types + for k in conf["vat"]: + Product.VATS += (float(conf["vat"][k]),) + # SERIES for k in conf["series"]: Invoice.SERIES[int(k)] = conf["series"][k] @@ -55,10 +60,10 @@ def load_config(): templatefile = path.join(confile, templatefile) # INVOICE LEVEL TAXES (like IRPF in Spain) - tax = [] + tax = () for k in conf["taxes"]: - tax.append(Tax(k, conf.getfloat("taxes",k))) - Invoice.DEFAULT_TAXES = tuple(tax) + tax += (Tax(k, conf.getfloat("taxes",k)),) + Invoice.DEFAULT_TAXES = tax # DATABASE Invoice.DB_FILE = path.join(basedir, "invoice.db") @@ -112,7 +117,26 @@ def new_invoice(): @command def summarize(xlsx=False, year=None, quarter=None): invoices = Invoice.load_by_date(year, quarter) - rows = map(lambda x: x.to_row(), invoices) + rows = sorted((map(lambda x: x.to_row(), invoices)), + key=lambda x: x["type"]) + + keys = list(rows[0].keys()) + for r in rows: + for k in r.keys(): + if k not in keys: + # TODO: + # Inserts all the taxes at the end, but this is not cool + # because it needs information about how is the invoice + # arranged + # Maybe move this to a static function in invoices and call it + # summary and make it work with some logic like: create the + # keys first and then go setting them in order + keys.insert(-1, k) + import sys + wrtr = DictWriter(sys.stdout, keys) + wrtr.writeheader() + for r in rows: + wrtr.writerow(r) if __name__ == "__main__": |