misc. invoice fixes

This commit is contained in:
Thomas Steen Rasmussen 2016-05-31 06:51:30 +02:00
parent f8ed60f8b6
commit ed79b8f73a
4 changed files with 18 additions and 18 deletions

View file

@ -6,6 +6,7 @@ from shop.pdf import generate_pdf_letter
from shop.email import send_invoice_email from shop.email import send_invoice_email
from shop.models import Order, Invoice from shop.models import Order, Invoice
from time import sleep from time import sleep
from decimal import Decimal
class Command(BaseCommand): class Command(BaseCommand):

View file

@ -79,17 +79,17 @@ class Order(CreatedUpdatedModel):
@property @property
def vat(self): def vat(self):
return self.total*0.2 return Decimal(self.total*0.2)
@property @property
def total(self): def total(self):
return self.products.aggregate( return Decimal(self.products.aggregate(
sum=Sum( sum=Sum(
models.F('orderproductrelation__product__price') * models.F('orderproductrelation__product__price') *
models.F('orderproductrelation__quantity'), models.F('orderproductrelation__quantity'),
output_field=models.IntegerField() output_field=models.IntegerField()
) )
)['sum'] )['sum'])
def get_coinify_callback_url(self, request): def get_coinify_callback_url(self, request):
return 'https://' + request.get_host() + str(reverse_lazy('shop:coinify_callback', kwargs={'pk': self.pk})) return 'https://' + request.get_host() + str(reverse_lazy('shop:coinify_callback', kwargs={'pk': self.pk}))

View file

@ -3,28 +3,26 @@
<table style="width:100%;"> <table style="width:100%;">
<tr> <tr>
<td style="text-align: right">Order number: {{ ordernumber }}</td> <td style="text-align: right">Order number: {{ invoice.order.pk }}</td>
</tr> </tr>
<tr> <tr>
<td style="text-align: right">Invoice number: {{ invoicenumber }}</td> <td style="text-align: right">Invoice number: {{ invoice.pk }}</td>
</tr> </tr>
<tr> <tr>
<td style="text-align: right">Date: {% now "j/n-Y" %}</td> <td style="text-align: right">Date: {% now "j/n-Y" %}</td>
</tr> </tr>
</table> </table>
<table style="width:100%;"> <table style="width:100%;" border=1>
<thead>
<tr> <tr>
<th> <td>
Name <b>Name
<th> <td>
Quantity <b>Quantity
<th> <td>
Price <b>Price
<th> <td>
Total <b>Total
<tbody>
{% for order_product in invoice.order.orderproductrelation_set.all %} {% for order_product in invoice.order.orderproductrelation_set.all %}
<tr> <tr>
<td> <td>
@ -40,7 +38,7 @@
<tr> <tr>
<td colspan="2"> <td colspan="2">
<td> <td>
<strong>Hereof VAT (25%)</strong> <strong>Danish VAT (25%)</strong>
<td> <td>
{{ order.vat|currency }} {{ order.vat|currency }}

View file

@ -1,5 +1,6 @@
from django import template from django import template
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from decimal import Decimal
register = template.Library() register = template.Library()
@ -7,7 +8,7 @@ register = template.Library()
@register.filter @register.filter
def currency(value): def currency(value):
try: try:
return "{0:.2f} DKK".format(int(value)) return "{0:.2f} DKK".format(Decimal(value))
except ValueError: except ValueError:
return False return False