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']