def return_rental(request):
    params = {}
    user = hmod.User.objects.get(id=request.urlparams[0])
    agent = hmod.Agent.objects.get(id=request.urlparams[1])

    returned_item = hmod.Item.objects.get(id=request.urlparams[2])
    rental_item = hmod.RentalItem.objects.get(item_id_id=returned_item.id,
                                              returns_id=None)
    rental = hmod.Rental.objects.get(id=rental_item.rental_id_id)

    #CREATE NEW INSTANCE OF RETURN
    new_return = hmod.Return()
    new_return.return_time = date.today()
    new_return.agent = agent
    new_return.rental = rental
    new_return.save()

    rental_item.returns = new_return
    rental_item.save()

    #SET UP DATES TO BE COMPARED
    mdate = rental.due_date.date()
    mdate = mdate.strftime("%Y-%m-%d")
    rdate = date.today()
    rdate = rdate.strftime("%Y-%m-%d")
    mdate1 = datetime.datetime.strptime(mdate, "%Y-%m-%d").date()
    rdate1 = datetime.datetime.strptime(rdate, "%Y-%m-%d").date()
    delta = 0

    #IF THE RETURN DATE IS GREATER THAN THE DUE DATE, DO THIS
    if mdate < rdate:
        days_late = date.today() - rental.due_date.date()
        delta = (rdate1 - mdate1).days
        fee = delta * (returned_item.standard_rental_price / 7)
        fee = round(fee, 2)
        status = 'Your return was a little late...'

        lf = hmod.LateFee()
        lf.amount = fee
        lf.return_fee = new_return
        lf.rental_item = rental_item
        lf.days_late = delta
        lf.save()

    #IF THE ITEM WAS RETURNED BEFORE THE DUE DATE, DO THIS
    else:
        status = 'You brought it back on time! Thanks!'
        lf = hmod.LateFee.objects.get(id=1)
        print('its not overdue')

    params['status'] = status
    params['delta'] = delta
    params['new_return'] = new_return
    params['user'] = user
    params['rental'] = rental
    params['returned_item'] = returned_item
    params['agent'] = agent
    params['lf'] = lf
    return templater.render_to_response(request, 'rentals.return_rental.html',
                                        params)
             [
                 26.50,
                 hmod.Return.objects.get(id=1),
                 hmod.RentalItem.objects.get(id=1), 4
             ],
             [
                 13.00,
                 hmod.Return.objects.get(id=1),
                 hmod.RentalItem.objects.get(id=2), 1
             ],
             [
                 5.00,
                 hmod.Return.objects.get(id=1),
                 hmod.RentalItem.objects.get(id=3), 1
             ]]:
    latefee = hmod.LateFee()
    latefee.amount = data[0]
    latefee.return_fee = data[1]
    latefee.rental_item = data[2]
    latefee.days_late = data[3]
    latefee.save()

#Create DamageFee
for data in [[
        500.00,
        hmod.Return.objects.get(id=1),
        hmod.RentalItem.objects.get(id=1),
        'Irreparable damage, cannot be fixed'
],
             [
                 5.00,
Exemplo n.º 3
0
    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],
    ["25", False, 3, "50.00", 1],
]:

    lf = hmod.LateFee()
    lf.days_late = data[0]

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

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

    lf.save()

################################      Configuration Parameters

for data in [
    [".23"],
    [".20"],
Exemplo 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)