def return_damageFee(request):
    params = {}

    user = hmod.User.objects.get(id=request.urlparams[0])
    agent = hmod.Agent.objects.get(id=request.urlparams[1])
    return_fee = hmod.Return.objects.get(id=request.urlparams[2])
    rental = hmod.Rental.objects.get(id=request.urlparams[3])
    item = hmod.Item.objects.get(id=request.urlparams[4])
    rental_item = hmod.RentalItem.objects.get(rental_id_id=rental.id,
                                              item_id_id=item.id)

    form = DamageForm()
    if request.method == 'POST':
        form = DamageForm(request.POST)
        if form.is_valid():
            DmgFee = hmod.DamageFee()
            DmgFee.amount = form.cleaned_data['Fee']
            DmgFee.return_fee = return_fee
            DmgFee.rental_item = rental_item
            DmgFee.description = form.cleaned_data['Description']
            DmgFee.save()
            return HttpResponseRedirect(
                '/homepage/rentals.return_item/{}/{}/'.format(
                    user.id, agent.id))
    params['form'] = form
    params['user'] = user
    params['agent'] = agent
    params['return_fee'] = return_fee
    params['rental'] = rental
    params['item'] = item
    params['rental_item'] = rental_item
    return templater.render_to_response(request,
                                        'rentals.return_damageFee.html',
                                        params)
        hmod.Return.objects.get(id=1),
        hmod.RentalItem.objects.get(id=1),
        'Irreparable damage, cannot be fixed'
],
             [
                 5.00,
                 hmod.Return.objects.get(id=1),
                 hmod.RentalItem.objects.get(id=2),
                 'Tears in the fabric, must be mended'
             ],
             [
                 50.00,
                 hmod.Return.objects.get(id=1),
                 hmod.RentalItem.objects.get(id=3), 'Some broken glass'
             ]]:
    damagefee = hmod.DamageFee()
    damagefee.amount = data[0]
    damagefee.return_fee = data[1]
    damagefee.rental_item = data[2]
    damagefee.description = data[3]
    damagefee.save()

#Create Bulk_Product
for data in [[
        'Colonial Honey', '12 oz. of real honey', 'Food', 10.00, 250,
        hmod.Photograph.objects.get(id=1)
],
             [
                 'Hand-woven Basket', 'A hand-made basket', 'Misc.', 25.00,
                 500,
                 hmod.Photograph.objects.get(id=1)
Ejemplo n.º 3
0
    ri.discount_percent = data[3]
    ri.rental_product_id = data[4]

    ri.amount = data[5]
    ri.order_id = data[6]
    ri.save()

#################################      Damage Fee

for data in [
    ["dents and scrapes", False, 3, "50.43", 1],
    ["paint spilled", True, 1, "43", 2],
    ["grass stains", False, 2, "10.00", 3],
]:

    df = hmod.DamageFee()
    df.description = data[0]

    df.waived = data[1]
    df.rental_item_id = data[2]

    df.amount = data[3]
    df.order_id = data[4]

    df.save()

#################################      Late Fee

for data in [
    ["5", False, 1, "10.43", 3],
    ["3", True, 2, "4.50", 2],
Ejemplo n.º 4
0
def fees(request):
    params = {}

    p = request.urlparams[0]
    g = request.urlparams[1]
    form = feesForm(initial={'orderID': p, 'RentalItemID': g})
    action = '/homepage/rental_return.fees/{}/'.format(p) + '{}/'.format(g)
    # rentalitem = hmod.RentalItem.objects.get(id=request.urlparams[0])
    # print(rentalitem)

    ri = hmod.RentalItem.objects.get(id=g)

    # function to figure out the days late
    def days_between(d1, d2):
        return int((d1 - d2).days)

    # set the days late using the previous function
    dl = days_between(ri.date_in, ri.date_due)
    # make sure to never spit back a negative number of days late
    if dl <= 0:
        days_late = 0
    else:
        days_late = dl

    lateFeeVar = int(
        ri.rental_product.cost) * 5 * .01 * days_late  #   5% per day late

    if request.method == 'POST':
        form = feesForm(request.POST)
        if form.is_valid():
            try:
                lateFee = hmod.LateFee()
                lateFee.waived = form.cleaned_data['lateWaived']
                lateFee.days_late = days_late
                lateFee.amount = lateFeeVar
                # lateFee.order_id = hmod.Order.objects.get(id = p)
                lateFee.order_id = p
                lateFee.rental_item = ri
                lateFee.save()

                damageFee = hmod.DamageFee()
                damageFee.amount = form.cleaned_data['damageFee']
                damageFee.waived = form.cleaned_data['waived']
                damageFee.description = form.cleaned_data['description']
                damageFee.order_id = form.cleaned_data['orderID']
                damageFee.rental_item_id = form.cleaned_data['RentalItemID']
                damageFee.save()

            except hmod.RentalItem.DoesNotExist:
                error = "<p class='bg-danger'>Invalid rental id. Try again or give up.</p>"
                params['error'] = error
                params['form'] = form
                return templater.render_to_response(request,
                                                    'rental_return.html',
                                                    params)

            return HttpResponseRedirect(
                '/homepage/rental_return/{}/'.format('success'))

    params['lateFee'] = lateFeeVar
    params['days_late'] = days_late

    rental = hmod.RentalItem.objects.get(id=request.urlparams[0])
    product = hmod.RentalProduct.objects.get(id=rental.rental_product.id)
    rentalItems = hmod.RentalItem.objects.get(rental_product=product.id)
    damages = hmod.DamageFee.objects.filter(rental_item=rentalItems.id)
    params['rental'] = rental
    params['product'] = product
    params['rentalItems'] = rentalItems
    params['damages'] = damages

    params['success'] = ""
    error = ''
    params['error'] = error
    # params['rentalitem'] = rentalitem
    params['form'] = form
    params['action'] = action
    return templater.render_to_response(request, 'rental_return.fees.html',
                                        params)