From 9dbe39a35f3e3b7d42ac46f4610572c61d7c533b Mon Sep 17 00:00:00 2001 From: kj1352 Date: Thu, 21 Jul 2022 18:12:59 +0530 Subject: [PATCH] Added invoice total with tax property --- invoice/models.py | 6 +++--- invoice/serializers.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/invoice/models.py b/invoice/models.py index ed0e675..94ca333 100644 --- a/invoice/models.py +++ b/invoice/models.py @@ -13,12 +13,12 @@ class Invoice(models.Model): is_archived = models.BooleanField(default=False) @property - def invoice_total_without_tax(self): - items = Item.objects.filter(invoice=self.pk) + def invoice_total_with_tax(self): + items = self.items.all() total = 0 for item in items: total += item.item_total - return total + return total + (total * self.project.client.address.tax_type.percentage / 100) def __str__(self): return self.invoice_id diff --git a/invoice/serializers.py b/invoice/serializers.py index d726e22..f2e8159 100644 --- a/invoice/serializers.py +++ b/invoice/serializers.py @@ -17,4 +17,4 @@ class InvoiceSerializer(WritableNestedModelSerializer): class Meta: model = Invoice fields = ['id', 'title', 'project', 'invoice_id', 'raised_date', 'due_date', 'paid_date', 'is_archived', - 'invoice_total_without_tax', 'items'] + 'invoice_total_with_tax', 'items']