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))
def accountToCoupon(request): if request.method == "POST": try: tmp = request.POST["value"].replace(",", ".") val = decimal.Decimal(moneyfmt(decimal.Decimal(tmp), places=2, dp=".", sep="")) if val > 0: cacc = CouponAccount.objects.get(user=request.user) # Fehler wenn Guthaben nicht ausreicht if cacc.balance < val: return render_to_response( "error.html", {"errormsg": "Ihr Guthaben reicht nicht aus."}, context_instance=RequestContext(request), ) # Coupon erstellen c = Coupon(creator=request.user) c.isgift = True c.isValid = True c.valueMoney = val c.code = get_random_code() c.minGoodsValue = 0 c.save() # Wert vom Guthabenkonto abziehen cacc.balance += val * -1 cacc.save() # Transaktion speichern ctrans = CouponAccountTransaction(cacc=cacc) ctrans.amount = val * -1 ctrans.message = "Gutschein %s erstellt." % c.code ctrans.isValid = True ctrans.save() sendCreatedMail(c, request.user.email) else: return render_to_response( "error.html", {"errormsg": "Der Gutscheinwert muss positiv sein."}, context_instance=RequestContext(request), ) except: return render_to_response( "error.html", {"errormsg": "Der angegebene Gutscheinwert ist nicht gueltig."}, context_instance=RequestContext(request), ) return HttpResponseRedirect(reverse("shoppy_coupon_account"))
def orderOverview(request): cart = requestCurCart(request) if int(cart.get_item_count()) > 0: try: order = Order.objects.get(id=request.session['order_id'], user=request.user,order_date__isnull=True) # Wurde Bestellung abgeschickt? if request.method == 'POST': order.order_date = datetime.datetime.now() # copy the current shipping fee order.shipping_cost = decimal.Decimal('%s' % order.cart.get_shipping_fee()) order.save() order.billnumber() #Speichern, dass Cart bestellt wurde order.cart.isActive = False order.cart.isOrdered = True order.cart.save() # Kopie anlegen, wenn Cart einen Namen hat # ansonsten kann ein Cart doppelt bestellt werden if order.cart.name: # neuen Cart mit alten Cart-Daten erstellen newcart = Cart() newcart.name = order.cart.name newcart.user = order.cart.user newcart.save() # Produkte aus altem Cart in neuen legen for cp in CartProduct.objects.filter(cart=order.cart): newcp = CartProduct(cart=newcart) newcp.product = cp.product newcp.amount = cp.amount newcp.save() # MixedProdukte aus altem Cart in neuen legen for mcp in CartProduct.objects.filter(cart=order.cart): newmcp = CartMixProduct(cart=newcart) newmcp.product = mcp.product newmcp.amount = mcp.amount newmcp.save() # Die verwendeten Gutscheine entwerten ccs = CartCoupon.objects.filter(cart=order.cart) for cc in ccs: # ist der Gutschein ein einmaliger Gutschein? if cc.coupon.isgift == True: cc.coupon.isValid = False cc.coupon.valid_to = datetime.datetime.now() cc.coupon.save() # Restguthaben von Gutscheinen dem Guthabenkonto gutschreiben if decimal.Decimal(order.cart.get_total_with_fee()) < decimal.Decimal('0.00'): try: cacc = CouponAccount.objects.get(user=request.user) except CouponAccount.DoesNotExist: cacc = CouponAccount(user=request.user, balance=0 ) cacc.save() ctrans = CouponAccountTransaction(cacc=cacc) ctrans.amount = decimal.Decimal(order.cart.get_total_with_fee()) * -1 ctrans.message = 'Restguthaben von Bestellung %s' % order.billnumber() ctrans.isValid = False ctrans.save() cacc.balance += decimal.Decimal(order.cart.get_total_with_fee()) * -1 cacc.save() sendOrderMail(order) sendOrderMailAdmin(order) if order.paymenttype.code == 'bill': return HttpResponseRedirect(reverse('shoppy_order_thanks')) else: return HttpResponseRedirect(reverse('shoppy_custom_order_view',args=[order.id])) cart = order.cart cartitems = CartProduct.objects.all().filter(cart=cart) cartmixitems = CartMixProduct.objects.all().filter(cart=cart) cartcoupon = CartCoupon.objects.all().filter(cart=cart) couponmoney = decimal.Decimal('0.00') for cc in cartcoupon: couponmoney += cc.coupon.valueMoney couponmoney = moneyfmt(couponmoney, places=2, dp=',', sep='.') return render_to_response('shop/overview.html',{ 'order': order, 'couponmoney': couponmoney, 'cartitems': cartitems, 'cartmixitems': cartmixitems, 'hideRightNavi':True, 'hideLeftNavi':True },context_instance=RequestContext(request)) except Order.DoesNotExist, KeyError: return render_to_response('error.html', { 'errormsg': 'Oooops. Da lief wohl was falsch!', },context_instance=RequestContext(request))