everything is much better now!

This commit is contained in:
seba 2010-12-02 13:31:52 +01:00
parent 35301915be
commit c05fe944c0
3 changed files with 16 additions and 8 deletions

View File

@ -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

View File

@ -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

Binary file not shown.