diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2020-09-16 21:14:22 +0200 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2020-09-16 21:16:48 +0200 |
commit | 14b4552f1e974374ac230566d6fd095628c6a14d (patch) | |
tree | ce9e84558be01c4eab33f619d00cded853a0ab21 /fracture | |
parent | 4b3f63fc34725d3d6f18813879b0929badb73ebe (diff) |
Add VAT summary
Diffstat (limited to 'fracture')
-rw-r--r-- | fracture/invoice.py | 17 |
1 files changed, 16 insertions, 1 deletions
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()) |