From 512be60da5c88813f8c3e334036f06290af22692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sun, 17 Mar 2019 15:31:15 +0100 Subject: [PATCH] Products can not be handed out if order is not paid. Fix #284. --- src/shop/models.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/shop/models.py b/src/shop/models.py index 0bdfb668..c6bcdc34 100644 --- a/src/shop/models.py +++ b/src/shop/models.py @@ -405,6 +405,7 @@ class Product(CreatedUpdatedModel, UUIDModel): # If there is no stock defined the product is generally available. return True + class OrderProductRelation(CreatedUpdatedModel): order = models.ForeignKey('shop.Order', on_delete=models.PROTECT) product = models.ForeignKey('shop.Product', on_delete=models.PROTECT) @@ -415,6 +416,12 @@ class OrderProductRelation(CreatedUpdatedModel): def total(self): return Decimal(self.product.price * self.quantity) + def clean(self): + if self.handed_out and not self.order.paid: + raise ValidationError( + 'Product can not be handed out when order is not paid.' + ) + class EpayCallback(CreatedUpdatedModel, UUIDModel): class Meta: