handle orders with no products

This commit is contained in:
Thomas Steen Rasmussen 2016-06-04 09:49:22 +02:00
parent fc077a43df
commit 7d679beae6

View file

@ -90,6 +90,7 @@ class Order(CreatedUpdatedModel):
@property @property
def total(self): def total(self):
if self.products.all():
return Decimal(self.products.aggregate( return Decimal(self.products.aggregate(
sum=Sum( sum=Sum(
models.F('orderproductrelation__product__price') * models.F('orderproductrelation__product__price') *
@ -97,6 +98,8 @@ class Order(CreatedUpdatedModel):
output_field=models.IntegerField() output_field=models.IntegerField()
) )
)['sum']) )['sum'])
else:
return False
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}))