|
@@ -1,5 +1,6 @@ |
|
|
from django.db import models |
|
|
from django.db import models |
|
|
from project.models import Project |
|
|
from project.models import Project |
|
|
|
|
|
from client.models import Client, Address, TaxType |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Invoice(models.Model): |
|
|
class Invoice(models.Model): |
|
@@ -19,6 +20,18 @@ class Invoice(models.Model): |
|
|
total += item.item_total |
|
|
total += item.item_total |
|
|
return total |
|
|
return total |
|
|
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
|
def invoice_total_after_tax(self): |
|
|
|
|
|
items = Item.objects.filter(invoice=self.pk) |
|
|
|
|
|
project = Project.objects.get(client=self.project) |
|
|
|
|
|
client = Client.objects.get(pk=project.client) |
|
|
|
|
|
address = Address.objects.get(pk=client.address) |
|
|
|
|
|
tax_type = TaxType.objects.get(pk=address.tax_type) |
|
|
|
|
|
total = 0 |
|
|
|
|
|
for item in items: |
|
|
|
|
|
total += item.item_total |
|
|
|
|
|
return total |
|
|
|
|
|
|
|
|
def __str__(self): |
|
|
def __str__(self): |
|
|
return self.invoice_id |
|
|
return self.invoice_id |
|
|
|
|
|
|
|
@@ -27,7 +40,7 @@ class Item(models.Model): |
|
|
name = models.TextField(blank=False, null=False) |
|
|
name = models.TextField(blank=False, null=False) |
|
|
amount = models.DecimalField(max_digits=15, decimal_places=2) |
|
|
amount = models.DecimalField(max_digits=15, decimal_places=2) |
|
|
quantity = models.IntegerField() |
|
|
quantity = models.IntegerField() |
|
|
invoice = models.ForeignKey(Invoice, on_delete=models.CASCADE) |
|
|
|
|
|
|
|
|
invoice = models.ForeignKey(Invoice, on_delete=models.CASCADE, related_name='items') |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def item_total(self): |
|
|
def item_total(self): |
|
|