from django.shortcuts import render, get_object_or_404, redirect
from osinacore.models import *
from billing.models import *
from osinacore.decorators import *

@staff_login_required
def delete_orderitem(request, orderitem_id):
    order_item = get_object_or_404(OrderItem, id=orderitem_id)
    order_id = order_item.order.order_id
    order_item.delete()
    return redirect('orderdetails', order_id=order_id)


@staff_login_required
def delete_payment_method_modal(request, method_id):
    method = get_object_or_404(PaymentType, id=method_id)
    if request.method == 'POST':
        method.delete()
        return redirect('paymentmethods')


    context = {
        'method': method
    }
    
    return render(request, "delete_templates/delete-payment-method-modal.html", context)

