From 14b4552f1e974374ac230566d6fd095628c6a14d Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Wed, 16 Sep 2020 21:14:22 +0200 Subject: Add VAT summary --- fracture/invoice.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/fracture/invoice.py b/fracture/invoice.py index 295b7a8..0ccfec2 100644 --- a/fracture/invoice.py +++ b/fracture/invoice.py @@ -363,6 +363,20 @@ class Invoice: def total(self): return sum(p.total for p in self.products) + \ sum(self.base*t.ratio for t in self.taxes) + def summarize_vat(self): + pvat = lambda p: p.vat + vs = groupby(sorted(self.products, key=pvat), key=pvat) + + res = () + + for vat, ps in vs: + ps = tuple(ps) + res += ({ + "vat": vat, + "base": Conf.round(sum(p.base for p in ps)), + "charged": Conf.round(sum(p.charged_vat for p in ps)), + },) + return res def to_dict(self): return { @@ -379,7 +393,8 @@ class Invoice: "base": self.base, "notes": self.notes, "total": Conf.round(self.total), - "vat-charged": self.vat_charged + "vat-charged": self.vat_charged, + "vat-summary": self.summarize_vat() } def to_json(self): return json.dumps(self.to_dict()) -- cgit v1.2.3