示例#1
0
def tryPointTransferOrder(orderid):
    try:
        order = Order.objects.get(id=orderid)
        try:
            to = TransferOrder.objects.get(order=order)
        except TransferOrder.DoesNotExist:
            try:
                acc = Account.objects.get(user=order.user)
            except Account.DoesNotExist:
                acc = Account(user=order.user, total_current=0, total_lifetime=0)
                acc.save()
            t = Transfer()
            t.account = acc
            t.amount = order.cart.get_points()
            acc.total_current += t.amount
            acc.total_lifetime += t.amount
            acc.save()
            t.isPositive = True
            t.isActive = True
            t.subject = 'Bestellung %s' % order.billnumber()
            t.save()
            to = TransferOrder(order=order, transfer=t)
            to.save()
            return True
    except Order.DoesNotExist:
        pass
    return False
示例#2
0
def pointstocash(request, ptc_id):
    msg = None
    if request.method == 'POST':
        points = request.POST['points']
        money = 0
        if points == '300':
            money = 5
        elif points == '800':
            money = 25
        elif points == '1500':
            money = 50
        pacc = Account.objects.get(user=request.user)
        if decimal.Decimal(pacc.total_current) >= decimal.Decimal(points):
            pacc.total_current -= decimal.Decimal(points)
            pacc.save()
            ptrans = Transfer(account=pacc)
            ptrans.amount = decimal.Decimal(points)
            ptrans.subject = u'%s ocs eingetauscht' % points
            ptrans.isPositive = False
            ptrans.isActive = True
            ptrans.save()
            ca = CouponAccount.objects.get(user=request.user)
            ca.balance += decimal.Decimal(money)
            ca.save()
            cat = CouponAccountTransaction(cacc=ca)
            cat.amount = decimal.Decimal(money)
            cat.message = u'%s ocs eingetauscht' % points
            cat.isValid = True
            cat.save()
            return HttpResponseRedirect(reverse('shoppy_points_account'))
    if ptc_id == '1':
        points = 300
        money = 5
    elif ptc_id == '2':
        points = 800
        money = 25
    elif ptc_id == '3':
        points = 1500
        money = 50
    else:
        return HttpResponseRedirect(reverse('shoppy_points_account'))

    pacc = Account.objects.get(user=request.user)
    if decimal.Decimal(pacc.total_current) < decimal.Decimal(points):
        msg = u'Sie haben leider nicht genug ocs.'
        
    return render_to_response('points/pointstocash.html',
                            {
                            'points': points,
                            'money': money,
                            'msg':msg,
                            'hideCart':True,
                            'hideSearch':True
                            },
                           context_instance=RequestContext(request))