Esempio n. 1
0
    },
    {
        'condition': 'Fair',
        'new_damage': 'False',
        'damage_fee': '10.00',
        'due_date': '2014-12-27'
    },
    {
        'condition': 'Fair',
        'new_damage': 'False',
        'damage_fee': '10.00',
        'due_date': '2014-11-04'
    },
]:

    d = hmod.RentalItem()
    for k, v in data.items():
        setattr(d, k, v)
    d.save()

# populating artisan items
for data in [
    {
        'area': 'Candle Maker',
        'name': 'Candle',
        'description': 'Description 1',
        'low_price': '10.00',
        'high_price': '35.74',
        'artisan_name': 'John',
        'photo': 'product1.jpg'
    },
        hmod.Item.objects.get(id=3),
        hmod.Return.objects.get(id=1)
    ], [hmod.Rental.objects.get(id=2),
        hmod.Item.objects.get(id=1), None],
    [hmod.Rental.objects.get(id=2),
     hmod.Item.objects.get(id=2), None],
    [hmod.Rental.objects.get(id=2),
     hmod.Item.objects.get(id=3), None],
    [hmod.Rental.objects.get(id=3),
     hmod.Item.objects.get(id=4), None],
    [hmod.Rental.objects.get(id=4),
     hmod.Item.objects.get(id=5), None],
    [hmod.Rental.objects.get(id=5),
     hmod.Item.objects.get(id=6), None]
]:
    ritem = hmod.RentalItem()
    ritem.rental_id = data[0]
    ritem.item_id = data[1]
    ritem.returns = data[2]
    ritem.save()

#Create Late Fee
for data in [[0, None, None, 0],
             [
                 26.50,
                 hmod.Return.objects.get(id=1),
                 hmod.RentalItem.objects.get(id=1), 4
             ],
             [
                 13.00,
                 hmod.Return.objects.get(id=1),
Esempio n. 3
0
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/')
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)
Esempio n. 5
0
photograph = hmod.Photograph()
photograph.imagePath = 'goves_breeches.jpg'
photograph.save()

itemSpec = hmod.ItemSpecifications()
itemSpec.name = 'Goves Breeches'
itemSpec.description = 'Red Breeches, with a 36 in waist'
itemSpec.price = '30.33'
itemSpec.manufacturer = 'Gove Allen'
itemSpec.user = user
itemSpec.photograph = photograph
itemSpec.category = cat
itemSpec.save()

rentalItem = hmod.RentalItem()
rentalItem.forSale = 'False'
rentalItem.quantityOnHand = '1'
rentalItem.cost = '20.22'
rentalItem.itemSpecifications = itemSpec
rentalItem.serialNumber = '123abc'
rentalItem.dateIn = '2015-03-07 12:01'
rentalItem.conditionNew = 'True'
rentalItem.notes = 'Goves Breeches Notes'
rentalItem.size = '36'
rentalItem.sizeModifier = '6'
rentalItem.gender = 'Male'
rentalItem.color = 'Red'
rentalItem.pattern = 'solid'
rentalItem.startYear = '1700-01-01'
rentalItem.endYear = '1750-01-01'