Skip to content
Snippets Groups Projects
Verified Commit ac708d90 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Add tables interface to invoice

parent 3187e373
No related branches found
No related tags found
No related merge requests found
Pipeline #58405 canceled
......@@ -10,6 +10,7 @@ from payments.models import BasePayment
from aleksis.core.mixins import ExtensibleModel, PureDjangoModel
from .base import Client
from ..tables import PurchasedItemsTable, TotalsTable
class InvoiceGroup(ExtensibleModel):
......@@ -44,3 +45,30 @@ class Invoice(BasePayment, PureDjangoModel):
constraints = [
models.UniqueConstraint(fields=["transaction_id", "group"], name="number_uniq_per_group")
]
@property
def purchased_items_table(self):
items = [i._asdict() for i in self.get_purchased_items()]
return PurchasedItemsTable(items)
@property
def totals_table(self):
tax_amounts = {}
for item in self.get_purchased_items():
tax_amounts.setdefault(item.tax_rate, 0)
tax_amounts[item.tax_rate] += item.price / (item.tax_rate + 100) * item.tax_rate
values = []
for tax_rate, total in tax_amounts:
values.append({
"name": _("Included VAT {} %").format(tax_rate),
"value": total,
"currency": self.currency,
})
values.append({
"name": _("Gross total"),
"value": self.total,
"currency": self.currency,
})
return TotalsTable(values)
import django_tables2 as tables
class PurchasedItemsTable(tables.Table):
sku = tables.Column()
name = tables.Column()
tax_rate = tables.Column()
quantity = tables.Column()
price = tables.Column()
currency = tables.Column()
class TotalsTable(tables.Table):
name = tables.Column()
value = tables.Column()
currency = tables.Column()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment