Exemplo n.º 1
0
def charge_remaining_post(request):
    if not request.method == 'POST':
        return bad_or_missing(request, _("No form found in request."))

    data = request.POST.copy()

    form = CustomChargeForm(data)
    if form.is_valid():
        data = form.cleaned_data
        try:
            orderitem = OrderItem.objects.get(pk=data['orderitem'])
        except OrderItem.DoesNotExist:
            return bad_or_missing(
                request,
                _("The orderitem you have requested doesn't exist, or you don't have access to it."
                  ))

        price = data['amount']
        line_price = price * orderitem.quantity
        orderitem.unit_price = price
        orderitem.line_item_price = line_price
        orderitem.save()
        #print("Orderitem price now: %s" % orderitem.line_item_price)

        order = orderitem.order

        if not order.shipping_cost:
            order.shipping_cost = Decimal("0.00")

        if data['shipping']:
            order.shipping_cost += data['shipping']

        order.recalculate_total()

        messages.add_message(
            request, messages.INFO,
            'Charged for custom product and recalculated totals.')

        notes = data['notes']
        if not notes:
            notes = 'Updated total price'

        order.add_status(notes=notes)

        return HttpResponseRedirect('/admin/shop/order/%i' % order.id)
    else:
        return render(request, 'admin/charge_remaining_confirm.html',
                      {'form': form})
Exemplo n.º 2
0
def charge_remaining_post(request):
    if not request.method == 'POST':
        return bad_or_missing(request, _("No form found in request."))
    
    data = request.POST.copy()
    
    form = CustomChargeForm(data)
    if form.is_valid():
        data = form.cleaned_data
        try:
            orderitem = OrderItem.objects.get(pk = data['orderitem'])
        except OrderItem.DoesNotExist:
            return bad_or_missing(request, _("The orderitem you have requested doesn't exist, or you don't have access to it."))
        
        price = data['amount']
        line_price = price*orderitem.quantity
        orderitem.unit_price = price
        orderitem.line_item_price = line_price
        orderitem.save()
        #print "Orderitem price now: %s" % orderitem.line_item_price
        
        order = orderitem.order
    
        if not order.shipping_cost:
            order.shipping_cost = Decimal("0.00")
    
        if data['shipping']:
            order.shipping_cost += data['shipping']
            
        order.recalculate_total()
        
        messages.add_message(request, messages.INFO, 'Charged for custom product and recalculated totals.')

        notes = data['notes']
        if not notes:
            notes = 'Updated total price'
            
        order.add_status(notes=notes)
        
        return HttpResponseRedirect('/admin/shop/order/%i' % order.id)
    else:
        ctx = RequestContext(request, {'form': form})
        return render_to_response('admin/charge_remaining_confirm.html',
                                  context_instance=ctx)
Exemplo n.º 3
0
def charge_remaining(request, orderitem_id):
    """Given an orderitem_id, this returns a confirmation form."""
    
    try:
        orderitem = OrderItem.objects.get(pk = orderitem_id)
    except OrderItem.DoesNotExist:
        return bad_or_missing(request, _("The orderitem you have requested doesn't exist, or you don't have access to it."))
        
    amount = orderitem.product.customproduct.full_price
        
    data = {
        'orderitem' : orderitem_id,
        'amount' : amount,
        }
    form = CustomChargeForm(data)
    ctx = RequestContext(request, {'form' : form})
    return render_to_response('payment/admin/charge_remaining_confirm.html',
                              context_instance=ctx)