Fix(views): Add sub total to purchase summary

This commit is contained in:
cosmos 2024-08-10 13:01:04 -05:00
parent 91bb2bce93
commit 6decc963f6
2 changed files with 12 additions and 3 deletions

View File

@ -41,6 +41,11 @@ class Sale(models.Model):
return f"{self.date} {self.customer}"
def get_total(self):
lines = self.saleline_set.all()
return sum([l.quantity * l.unit_price for l in lines])
class SaleLine(models.Model):
sale = models.ForeignKey(Sale, on_delete=models.CASCADE)

View File

@ -1,3 +1,7 @@
<p><b>Date:</b> {{ purchase.date }}</p>
<p><b>ID:</b> {{ purchase.id }}</p>
<p><b>Customer:</b> {{ purchase.customer }}</p>
<h1>Resumen de compra</h1>
<dl>
<dt>Date</dt> <dd>{{ purchase.date }}</dd>
<dt>ID</dt> <dd>{{ purchase.id }}</dd>
<dt>Customer</dt> <dd>{{ purchase.customer }}</dd>
<dt>Total</dt> <dd>{{ purchase.get_total }}</dd>
</dl>