def create(request): # params = {} order = hmod.Order() order.order_date = None order.phone = '' order.date_picked = None order.date_paid = None order.date_shipped = None order.tracking_number = '' order.save() return HttpResponseRedirect('/inventory/order.edit/{}'.format(order.id))
def create(request): ''' create: Creates empty order, sends user to edit page ''' params = {} # create order object order = hmod.Order() order.user = hmod.User() # save new order order.save() # send user to edit page return HttpResponseRedirect('/manager/orders.edit/{}'.format(order.id))
def create(request): if request.user.is_authenticated(): '''creates a new user''' order = hmod.Order() order_max = hmod.Order.objects.all().aggregate(Max('OrderNumber')) order.OrderNumber = order_max['OrderNumber__max'] + 1 order.orderDate = datetime.datetime.now() order.Phone = '' order.datePacked = datetime.datetime.now() order.datePaid = datetime.datetime.now() order.dateShipped = datetime.datetime.now() order.trackingNumber = '' order.save() return HttpResponseRedirect('/homepage/order.edit/{}'.format(order.id)) else: return HttpResponseRedirect('homepage/anon_user')
def create(request): '''Creates a new order''' order = hmod.Order() order.order_date = '2015-01-01' order.phone = '555-555-5555' order.date_packed = '2015-01-01' order.date_paid = '2015-01-01' order.date_shipped = '2015-01-01' order.tracking_number = 0 order.ship_address1 = 'Street Address' order.ship_address2 = 'Address 2' order.ship_city = 'City' order.ship_state = 'State' order.ship_zip = 00000 order.ship_country = 'Country' order.Agent_id = hmod.Agent.objects.first().id order.save() return HttpResponseRedirect('/homepage/order.edit/{}/'.format(order.id))
def create(request): if not request.user.is_authenticated(): return redirect('/homepage/login/?next=%s' % request.path) if not request.user.is_staff: return HttpResponseRedirect('/homepage/authentication') '''Creates a new order''' order = hmod.Order() # order.order_date = '' order.order_phone = '' order.phone_ext = '' # order.date_packed = '' # order.date_paid = '' # order.date_shipped = '' order.tracking_number = '' # order.customer = '' order.save() return HttpResponseRedirect('/homepage/orders.edit/{}/'.format(order.id))
def create(request): order = hmod.Order() order.order_date = "2000-01-01" order.phone = '000-000-0000' order.date_packed = '2000-01-01' order.date_paid = '2000-01-01' order.date_shipped = '2000-01-01' order.tracking_number = '0' order.ship_address1 = '' order.ship_address2 = ' ' order.ship_city = ' ' order.ship_state = ' ' order.ship_zip = '' order.ship_country = ' ' order.Agent_id = hmod.Agent.objects.first().id order.BulkDetail_id = hmod.BulkDetail.objects.first().id order.PersonalDetail_id = hmod.PersonalDetail.objects.first().id order.save() return HttpResponseRedirect('/homepage/order.edit/{}/'.format(order.id))
def charge_card(request): ''' charge_card: charges card via REST API, ''' params = {} params['form'] = CheckoutForm() # should i do this in the clean method? When do i want to charge?? # send the request with the data API_URL = 'http://dithers.cs.byu.edu/iscore/api/v1/charges' API_KEY = 'aa846fb6f04d54c4b952561399e40d84' r = requests.post( API_URL, data={ 'apiKey': API_KEY, 'currency': 'usd', 'amount': get_total(request), # my total 'type': 'Visa', 'number': creditcard, 'exp_month': exp_month, 'exp_year': exp_year, 'cvc': cvc, 'name': 'Cosmo Limesandal', 'description': 'Charge for cosmo@[email protected]', }) # parse response dictionary resp = r.json() if 'error' in resp: print('ERROR: ', resp['error']) else: # if order, create order object if len(request.session['shopping_cart']) > 0: order = hmod.Order() order.order_date = datetime.date.today() order.total = get_total(request) user = hmod.User.objects.get(id=request.user.id) order.user = user order.charge_id = resp['ID'] order.save() # if rental, create rental objects for each rental if len(request.session['rental_cart']) > 0: rental_ids = request.session['rental_cart'] for rental_id in rental_ids: r = hmod.Item.objects.get(id=rental_id) rental = hmod.Rental() rental.description = r.name rental.rental_date = datetime.date.today() rental.due_date = (datetime.date.today() + datetime.timedelta(days=30)) rental.available = False rental.charge_id = resp['ID'] user = hmod.User.objects.get(id=request.user.id) rental.user = user rental.item = r rental.save() # redirect to receipt return HttpResponseRedirect('/shop/checkout.receipt') return templater.render_to_response(request, 'enter_payment.html', params)
hmod.Agent.objects.get(id=3), hmod.Agent.objects.get(id=3), hmod.Agent.objects.get(id=3), hmod.User.objects.get(id=1), hmod.Address.objects.get(id=1), 'ch_78945edgadg', True, True ], [ '2015-01-25', 7202120147, '2015-01-27', '2015-01-27', '2015-01-27', 1288885, hmod.Agent.objects.get(id=3), hmod.Agent.objects.get(id=3), hmod.Agent.objects.get(id=3), hmod.User.objects.get(id=1), hmod.Address.objects.get(id=1), 'ch_45612487561', True, True ]]: order = hmod.Order() order.order_date = data[0] order.phone = data[1] order.date_packed = data[2] order.date_paid = data[3] order.date_shipped = data[4] order.tracking_number = data[5] order.packed_by = data[6] order.shipped_by = data[7] order.processed_by = data[8] order.customer = data[9] order.ships_to = data[10] order.payment = data[11] order.online_order = data[12] order.in_person_pickup = data[13] order.save()
], [ "1990-08-15", "801-898-6764", "2000-12-12", "2000-11-11", "2000-11-11", "453", 2, 5, 3, 2, 4, 2 ], [ "1990-08-15", "801-898-6764", "2000-12-12", "2000-11-11", "2000-11-11", "453", 1, 1, 1, 2, 1, 4 ], [ "1990-08-15", "801-898-6764", "2000-12-12", "2000-11-11", "2000-11-11", "453", 2, 3, 2, 2, 3, 4 ], ]: sp = hmod.Order() sp.order_date = data[0] sp.phone = data[1] sp.date_packed = data[2] sp.date_paid = data[3] sp.date_shipped = data[4] sp.tracking_number = data[5] sp.ships_to_id = data[6] sp.packed_by_id = data[7] sp.payment_processed_by_id = data[8] sp.shipped_by_id = data[9] sp.handled_by_id = data[10] sp.customer_id = data[11] sp.save() ################################# CART LINE ITEM
def process_request(request): template_vars = {} current_time = strftime("%Y-%m-%d %H:%M:%S", gmtime()) user = request.user #hmod.User.objects.get(id=request.urlparams[0]) form = OrderForm() prod_cart_objects = [] item_cart_objects = [] cart_products = request.session.get('shopping_cart') rent_total = 0 pur_total = 0 if not cart_products: pass else: for product in cart_products: qty = request.session['shopping_cart'][product] citem = hmod.Product.objects.get(id=product) print(citem) prod_cart_objects.append([citem.id, qty]) for item in prod_cart_objects: citem = hmod.Product.objects.get(id=item[0]) quant = item[1] pur_total = pur_total + (citem.current_price * quant) cart_items = request.session.get('shopping_cart_items') if not cart_items: pass else: for item in cart_items: qty = request.session['shopping_cart_items'][item] citem = hmod.Item.objects.get(id=item) print(citem) item_cart_objects.append([citem.id, qty]) for item in item_cart_objects: citem = hmod.Item.objects.get(id=item[0]) rent_total = rent_total + citem.standard_rental_price total = rent_total + pur_total print(prod_cart_objects) print(item_cart_objects) prod_cart_size = len(prod_cart_objects) item_cart_size = len(item_cart_objects) print(prod_cart_size) print(item_cart_size) if request.method == 'POST': form = OrderForm(request.POST) if form.is_valid(): print('Form data cleaned') print('Charge ID: ' + form.cleaned_data['charge']) address = hmod.Address() address.address_1 = form.cleaned_data['address_1'] address.address_2 = form.cleaned_data['address_2'] address.city = form.cleaned_data['city'] address.state = form.cleaned_data['state'] address.zip = form.cleaned_data['zip'] address.save() pur_total = 0 rent_total = 0 new_opo_id = 0 new_rent_id = 0 if not prod_cart_objects: pass else: opo = hmod.OnlinePurchaseOrder() opo.save() new_opo_id = opo.id for item in prod_cart_objects: citem = hmod.Product.objects.get(id=item[0]) quant = item[1] pur_total = pur_total + (citem.current_price * quant) opp = hmod.OnlinePurchaseProduct() opp.product_id = citem.id opp.onlinepurchaseorder = hmod.OnlinePurchaseOrder( id=opo.id) opp.quantity = quant opp.save() opo.total = pur_total opo.save() print( '########################################################################' ) if not item_cart_objects: pass else: rental = hmod.Rental() rental.rental_time = current_time mytime = datetime.strptime(current_time, "%Y-%m-%d %H:%M:%S") mytime += timedelta(hours=6) due_date = mytime.strftime("%Y-%m-%d %H:%M:%S") rental.due_date = due_date rental.save() print( '1111111111111111111111111111111111111111111111111111111111111' ) new_rent_id = rental.id for item in item_cart_objects: citem = hmod.Item.objects.get(id=item[0]) rent_total = rent_total + citem.standard_rental_price rentitem = hmod.RentalItem() rentitem.item_id_id = citem.id rentitem.rental_id_id = rental.id rentitem.returns = None rentitem.save() rental.total = rent_total rental.save() print( '########################################################################' ) total = rent_total + pur_total #print(customer) print( '1111111111111111111111111111111111111111111111111111111111111' ) order = hmod.Order() print('1') order.customer = hmod.User.objects.get(id=user.id) print('2') order.ships_to = hmod.Address.objects.get(id=address.id) print('3') #order.payment = form.cleaned_data['charge'] print('4') order.order_date = current_time print('5') order.save() if new_opo_id != 0: new_opo = hmod.OnlinePurchaseOrder.objects.get(id=new_opo_id) new_opo.order = order new_opo.save() if new_rent_id != 0: new_rental = hmod.Rental.objects.get(id=new_rent_id) new_rental.order = order new_rental.save() url = '/homepage/receipt/' + str(user.id) + '/' + str( order.id) + '/' + str(total) + '/' try: del request.session['shopping_cart'] except: pass try: del request.session['shopping_cart_items'] except: pass return HttpResponseRedirect(url) form = OrderForm( initial={ 'total': total, 'Card_Holder_Name': user.first_name + ' ' + user.last_name, }) template_vars['form'] = form template_vars['total'] = total return templater.render_to_response(request, 'checkout.html', template_vars)
r.due_date = data[2] user = hmod.User.objects.get(id=data[3]) r.user = user print('Rental:', r) r.save() ####################################### Orders ####################################### #Delete old Orders hmod.Order.objects.all().delete() #Create new Rentals: order_date, total, user for data in [ ['2015-03-06', '20.22', '1'], ['2015-03-06', '30.33', '2'], ['2015-03-06', '40.44', '3'], ['2015-03-06', '50.55', '4'], ]: o = hmod.Order() o.order_date = data[0] o.total = data[1] user = hmod.User.objects.get(id=data[2]) o.user = user o.save()
def process_cc(request): params = {} API_URL = 'http://dithers.cs.byu.edu/iscore/api/v1/charges' API_KEY = '5ac6b61282edafc1b039a0cd314d11d9' #All of this data will be dynamic during INTEX_II. For now, it's hardcoded. r = requests.post( API_URL, data={ 'apiKey': API_KEY, 'currency': 'usd', 'amount': '5.99', #Get from form 'type': 'Visa', 'number': '4732817300654', #Get from form 'exp_month': '10', #Get from form 'exp_year': '15', #Get from form 'cvc': '411', #Get from form 'name': 'Cosmo Limesandal', #Get from form 'description': 'Charge for [email protected]"', #Get from form }) resp = r.json() if 'error' in resp: # error? print("ERROR: ", resp['error']) return HttpResponseRedirect('/homepage/checkout/') else: a = hmod.Address.objects.all().order_by("-id").first() order = hmod.Order() order.phone = request.user.phone, order.order_date = datetime.today() order.date_paid = datetime.today() order.ships_to = a order.customer = request.user order.save() if "rental" in request.session['ptype']: rentalProductDictionary = {} orderTotal = 0 for k, v in request.session['rentalShopCartDict'].items(): rentalProductObject = hmod.RentalProduct.objects.get(id=k) rentalProductDictionary[rentalProductObject] = int(v) orderTotal += rentalProductObject.price_per_day * v ri = hmod.RentalItem() ri.date_out = datetime.today() ri.date_due = datetime.today() + timedelta(days=int(v)) ri.rental_product = hmod.RentalProduct.objects.get(id=k) ri.amount = rentalProductObject.price_per_day * v ri.order = hmod.Order.objects.all().order_by("-id").first() ri.discount_percent = 0 ri.save() params['orderTotal'] = orderTotal params['rentals'] = rentalProductDictionary ##Jong's Email Idea: user_email = request.user.email emailbody = templater.render(request, 'checkout_rental_email.html', params) send_mail("Thank You -- CHF Receipt", emailbody, '*****@*****.**', [user_email], html_message=emailbody, fail_silently=False) request.session['rentalShopCartDict'].clear() request.session.modified = True return HttpResponseRedirect('/homepage/thank_you/') else: productDictionary = {} orderTotal = 0 for k, v in request.session['shopCartDict'].items(): productObject = hmod.SerializedProduct.objects.get(id=k) productDictionary[productObject] = int(v) orderTotal += productObject.product_specification.price * v si = hmod.SaleItem() si.quantity = v si.product = hmod.SerializedProduct.objects.get(id=k) si.amount = productObject.product_specification.price * v si.order = hmod.Order.objects.all().order_by("-id").first() si.save() params['orderTotal'] = orderTotal params['products'] = productDictionary print(">>>>>>>>>>>>") print(request.session['shopCartDict']) ##Jong's Email Idea: user_email = request.user.email emailbody = templater.render(request, 'checkout_product_email.html', params) send_mail("Thank You -- CHF Receipt", emailbody, '*****@*****.**', [user_email], html_message=emailbody, fail_silently=False) request.session['shopCartDict'].clear() request.session.modified = True return HttpResponseRedirect('/homepage/thank_you/')