everything is much better now!
This commit is contained in:
parent
35301915be
commit
c05fe944c0
|
@ -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)
|
||||
|
||||
|
@ -58,13 +63,14 @@ class Purchase(models.Model):
|
|||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
BIN
k4ever/k4ever.db
BIN
k4ever/k4ever.db
Binary file not shown.
Loading…
Reference in New Issue