fixed Decimal issues, buying per api possible
This commit is contained in:
parent
ddf72146de
commit
1e825d96c4
|
@ -49,11 +49,8 @@ class BuyableItemHandler(BaseHandler):
|
|||
return rc.BAD_REQUEST # this is just the user being plain stupid
|
||||
order = Order()
|
||||
order.create(request.user)
|
||||
try:
|
||||
order.save()
|
||||
except Exception, e:
|
||||
return str(e)
|
||||
return rc.ALL_OK
|
||||
order.save()
|
||||
|
||||
for i in range(amount):
|
||||
p = Purchase.create(order, item, isDeposit=False)
|
||||
p.save()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
# Create your models here.
|
||||
class BuyableType(models.Model):
|
||||
|
@ -20,7 +21,7 @@ class Buyable(models.Model):
|
|||
buyableType = models.ManyToManyField(BuyableType)
|
||||
|
||||
def hasDeposit(self):
|
||||
return self.deposit > 0
|
||||
return self.deposit > 0.0
|
||||
|
||||
def createPurchase(self, isDeposit=False):
|
||||
p = Purchase()
|
||||
|
@ -47,7 +48,7 @@ class Order(models.Model):
|
|||
|
||||
def create(self, user=None):
|
||||
models.Model.__init__(self)
|
||||
self.price = 0.0
|
||||
self.price = Decimal(0)
|
||||
self.dateTime = datetime.datetime.now()
|
||||
if user:
|
||||
self.user = user
|
||||
|
@ -58,7 +59,7 @@ class Order(models.Model):
|
|||
self.price += item.price
|
||||
|
||||
def updatePrice(self, commit=False, updateBalance=False):
|
||||
self.price = 0.0
|
||||
self.price = Decimal(0)
|
||||
for item in self.purchase_set.all():
|
||||
self.price += item.price
|
||||
if commit or updateBalance:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
import re
|
||||
from decimal import Decimal, InvalidOperation
|
||||
|
||||
#class CurrencyField(forms.IntegerField):
|
||||
# default_error_message = {
|
||||
|
@ -56,8 +57,8 @@ class CurrencyField (forms.RegexField):
|
|||
#return value
|
||||
value = value.replace(",", ".")
|
||||
try:
|
||||
value = float(value)
|
||||
except (ValueError, TypeError):
|
||||
value = Decimal(value)
|
||||
except (ValueError, TypeError, InvalidOperation):
|
||||
raise ValidationError("Bitte gib eine Zahl ein")
|
||||
# if not self.allowPerCent:
|
||||
# tmpval = 100.0*value
|
||||
|
@ -68,4 +69,4 @@ class CurrencyField (forms.RegexField):
|
|||
return value
|
||||
def clean(self, value):
|
||||
value = super(CurrencyField, self).clean(value)
|
||||
return float(value)
|
||||
return Decimal(value)
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
from django.db import models
|
||||
from django.db.models.signals import post_save
|
||||
from django.contrib.auth.models import User
|
||||
from decimal import Decimal
|
||||
|
||||
class UserProfile(models.Model):
|
||||
user = models.ForeignKey(User, unique=True)
|
||||
balance = models.DecimalField(max_digits=9, decimal_places=2, default=0.0)
|
||||
balance = models.DecimalField(max_digits=9, decimal_places=2, default=Decimal(0))
|
||||
|
||||
def __unicode__(self):
|
||||
return "%s (Kontostand: %s)" % (self.user ,self.balance)
|
||||
|
|
|
@ -9,4 +9,4 @@ class TransactionForm(forms.ModelForm):
|
|||
exclude = ('user', 'dateTime', 'checked')
|
||||
def clean_amount(self):
|
||||
data = self.cleaned_data['amount']
|
||||
return data
|
||||
return data
|
||||
|
|
Loading…
Reference in New Issue