summaryrefslogtreecommitdiff
path: root/fracture
diff options
context:
space:
mode:
Diffstat (limited to 'fracture')
-rw-r--r--fracture/invoice.py17
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())