def get_total_nofee_notax(self): itemlist = CartProduct.objects.all().filter(cart=self) total = 0 for item in itemlist: total += item.amount * (item.product.price / (item.product.taxClass.percent+100) * 100) for mitem in CartMixProduct.objects.all().filter(cart=self): total += mitem.amount * (decimal.Decimal(mitem.product.get_price()) * decimal.Decimal('0.19')) val = moneyfmt(total + decimal.Decimal('0.0049'), places=4, dp='.', sep='') return decimal.Decimal(moneyfmt(decimal.Decimal('%s' % val), places=2, dp='.', sep=''))
def get_couponmoney_str(self): cartcoupon = CartCoupon.objects.all().filter(cart=self) couponmoney = decimal.Decimal('0.00') for cc in cartcoupon: couponmoney += cc.coupon.valueMoney couponmoney = moneyfmt(couponmoney, places=2, dp=',', sep='.') return '%s' % couponmoney
def get_tax_total_with_fee_str(self): total = decimal.Decimal(self.get_total_with_fee()) / 119 * 19 total = decimal.Decimal(total) - decimal.Decimal('0.0049') if total < decimal.Decimal('0'): total = decimal.Decimal('0') val = '%s' % moneyfmt(total, places=2, dp=',', sep='') return '%s' % val
def cashout(request): cmsg = None refacc = RefAccount.objects.get(user=request.user) if request.method == "POST": data = request.POST tmp = data["amount"] tmp = tmp.replace(",", ".") amount = decimal.Decimal(moneyfmt(decimal.Decimal(tmp), places=2, dp=".")) if amount <= refacc.balance: rat = RefAccountTransaction(racc=refacc) rat.amount = amount * -1 rat.message = "Auszahlung" rat.save() c = Cashout(user=request.user) c.accowner = data["owner"] c.accnumber = data["number"] c.bankcode = data["code"] c.amount = amount c.refacctrans = rat c.save() rat.message = "Auszahlung %s" % c.id rat.save() refacc.balance -= amount refacc.save() cmsg = u"Auszahlung von %s EUR wurde beantragt." % amount return render_to_response( "referral/cashout.html", {"refacc": refacc, "cmsg": cmsg, "hideCart": True, "hideSearch": True}, context_instance=RequestContext(request), )
def get_total_lifetime(userid): try: orders = Order.objects.filter(user__id=userid,paid_date__isnull=False) total = 0 for order in orders: total += order.cart.get_total_nofee_notax() total = total * decimal.Decimal('0.1') val = '%s' % moneyfmt(total, places=2, dp=',', sep='') #val = moneyfmt(total + decimal.Decimal('0.0049'), places=4, dp='.', sep='') #return decimal.Decimal(moneyfmt(decimal.Decimal('%s' % val), places=2, dp='.', sep='')) return '%s' % val except Order.DoesNotExist: return '0,00 EUR'
def cartDisplay(request): cart = requestCurCart(request) cproducts = CartProduct.objects.all().filter(cart=cart) cmixes = 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='.') context = RequestContext(request, { 'cart': cart, 'cproducts': cproducts, 'cmixproducts': cmixes, 'couponmoney': couponmoney }) return render_to_response('shop/cart.html', context)
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 cstOrderOverview(request, orderid): try: if request.user.is_staff: order = Order.objects.get(order_date__isnull=False,id=orderid) else: order = Order.objects.get(user=request.user,order_date__isnull=False,id=orderid) cartcoupon = CartCoupon.objects.all().filter(cart=order.cart) couponmoney = decimal.Decimal('0.00') for cc in cartcoupon: couponmoney += cc.coupon.valueMoney couponmoney = moneyfmt(couponmoney, places=2, dp=',', sep='.') except Order.DoesNotExist: raise Http404 return render_to_response('shop/cst_order_overview.html',{ 'order': order, 'couponmoney':couponmoney, 'hideRightNavi':True, 'hideLeftNavi':True} ,context_instance=RequestContext(request))
def get_shipping_fee_str(self): s = Settings.objects.get(name=settings.SHOPPY_SHOP) tmp = '%s' % self.get_shipping_fee() val = moneyfmt(decimal.Decimal(tmp), places=2, dp=',', sep='') return '%s %s' % (val, s.shippingchargescur.code)
def get_price_str(self): return '%s EUR' % moneyfmt(decimal.Decimal(self.get_price()), places=2, dp=',')
def get_total_with_fee_str(self): val = '%s' % moneyfmt(decimal.Decimal(self.get_total_with_fee()), places=2, dp=',', sep='') return '%s' % val
def get_ml100price_str(self): return moneyfmt(decimal.Decimal(self.get_price()) / self.get_ml() * 100, places=2, dp=',')
def get_total_nofee_notax_str(self): total = self.get_total_nofee_notax() val = '%s' % moneyfmt(total, places=2, dp=',', sep='') return '%s' % val
def get_price_str(self): tmp = decimal.Decimal(self.get_price) price = moneyfmt(tmp, places=2, dp=',') if price == ',00': price = '0,00' return '%s' % (price)
def get_total_str(self): return '%s' % moneyfmt(self.get_total(), places=2, dp=',', sep='.')
def get_price(self): price = moneyfmt(self.product.price * self.amount, places=2, dp=',', sep='.') return u'%s' % (price)
def get_price_str(self): price = moneyfmt(decimal.Decimal(self.product.get_price()) * self.amount, places=2, dp=',', sep='.') return u'%s' % price
def get_price_notax_str(self): price = moneyfmt(self.product.get_price_notax() * self.amount, places=2, dp=',', sep='.') return u'%s' % price
def get_price_notax_str(self): price = moneyfmt(self.get_price_notax(), places=2, dp=',') return '%s' % price
def get_valuemoney_str(self): return "%s" % (moneyfmt(self.valueMoney, places=2, dp=",", sep="."))
def get_amount_str(self): return '%s %s' % (moneyfmt(self.amount, places=2, dp=',', sep='.'), settings.SHOPPY_DEFAULT_CURRENCY_CODE)
def get_balance_str(self): return '%s' % moneyfmt(self.balance, places=2, dp=',', sep='.')
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))