diff --git a/k4ever/buyable/models.py b/k4ever/buyable/models.py index aba9d77..d9025ac 100644 --- a/k4ever/buyable/models.py +++ b/k4ever/buyable/models.py @@ -37,7 +37,7 @@ class Order(models.Model): price = models.FloatField() dateTime = models.DateTimeField() - def resetWithUser(self, user=None): + def create(self, user=None): models.Model.__init__(self) self.price = 0.0 self.dateTime = datetime.datetime.now() @@ -49,6 +49,11 @@ class Order(models.Model): self.purchase.add(item) self.price += item.price + def updatePrice(self): + self.price = 0.0 + for item in self.purchase_set.all(): + self.price += item.price + def __unicode__(self): return "Price %s, User %s" % (self.price, self.user) @@ -57,14 +62,15 @@ class Purchase(models.Model): price = models.FloatField() isDeposit = models.BooleanField() buyable = models.ForeignKey(Buyable) - - def create(order, buyable): + + @staticmethod + def create(order, buyable, isDeposit=False): p = Purchase() p.order = order if isDeposit: - p.price = self.deposit + p.price = buyable.deposit else: - p.price = self.price + p.price = buyable.price p.dateTime = datetime.datetime.now() p.buyable = buyable diff --git a/k4ever/buyable/views.py b/k4ever/buyable/views.py index 753a293..d4b35e8 100644 --- a/k4ever/buyable/views.py +++ b/k4ever/buyable/views.py @@ -35,17 +35,19 @@ def buyItem(request, itemid, buymode=""): "only/deposit" only deposit """ order = Order() - order.resetWithUser(user) + order.create(user) order.save() # for the id! if buymode == "" or buymode == "with/deposit": - p = item.createPurchase(isDeposit=False) + p = Purchase.create(order, item, isDeposit=False) p.order = order p.save() # TANNEK! if buymode == "with/dopsit" or buymode == "only/deposit": if buymode == "with/deposit" or buymode == "only/deposit": - p = item.createPurchase(isDeposit=True) + p = Purchase.create(order, item, isDeposit=True) p.order = order p.save() + order.updatePrice() + order.save() return HttpResponseRedirect("/store/bought/%s/" % (order.id)) @login_required diff --git a/k4ever/k4ever.db b/k4ever/k4ever.db index 15e2887..1c88490 100644 Binary files a/k4ever/k4ever.db and b/k4ever/k4ever.db differ