@@ -13,12 +13,12 @@ class Invoice(models.Model): | |||||
is_archived = models.BooleanField(default=False) | is_archived = models.BooleanField(default=False) | ||||
@property | @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 | total = 0 | ||||
for item in items: | for item in items: | ||||
total += item.item_total | total += item.item_total | ||||
return total | |||||
return total + (total * self.project.client.address.tax_type.percentage / 100) | |||||
def __str__(self): | def __str__(self): | ||||
return self.invoice_id | return self.invoice_id | ||||
@@ -17,4 +17,4 @@ class InvoiceSerializer(WritableNestedModelSerializer): | |||||
class Meta: | class Meta: | ||||
model = Invoice | model = Invoice | ||||
fields = ['id', 'title', 'project', 'invoice_id', 'raised_date', 'due_date', 'paid_date', 'is_archived', | fields = ['id', 'title', 'project', 'invoice_id', 'raised_date', 'due_date', 'paid_date', 'is_archived', | ||||
'invoice_total_without_tax', 'items'] | |||||
'invoice_total_with_tax', 'items'] |