@require_level('staff')
@require_POST
def sale_validation(request, course_id):
 try:
  invoice_number = request.POST['invoice_number']
 except KeyError:
  return HttpResponseBadRequest('Missing required invoice_number parameter')
 try:
  invoice_number = int(invoice_number)
 except ValueError:
  return HttpResponseBadRequest('invoice_number must be an integer, {value} provided'.format(value=invoice_number))
 try:
  event_type = request.POST['event_type']
 except KeyError:
  return HttpResponseBadRequest('Missing required event_type parameter')
 course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id)
 try:
  obj_invoice = CourseRegistrationCodeInvoiceItem.objects.select_related('invoice').get(invoice_id=invoice_number, course_id=course_id)
  obj_invoice = obj_invoice.invoice
 except CourseRegistrationCodeInvoiceItem.DoesNotExist:
  return HttpResponseNotFound(_("Invoice number '{num}' does not exist.").format(num=invoice_number))
 if (event_type == 'invalidate'):
  return invalidate_invoice(obj_invoice)
 else:
  return re_validate_invoice(obj_invoice)

@ require_level ( 'staff' ) @ require_POST def sale_validation ( request , course_id ) : try : invoice_number = request . POST [ 'invoice_number' ] except KeyError : return HttpResponseBadRequest ( 'Missing required invoice_number parameter' ) try : invoice_number = int ( invoice_number ) except ValueError : return HttpResponseBadRequest ( 'invoice_number must be an integer, {value} provided' . format ( value = invoice_number ) ) try : event_type = request . POST [ 'event_type' ] except KeyError : return HttpResponseBadRequest ( 'Missing required event_type parameter' ) course_id = SlashSeparatedCourseKey . from_deprecated_string ( course_id ) try : obj_invoice = CourseRegistrationCodeInvoiceItem . objects . select_related ( 'invoice' ) . get ( invoice_id = invoice_number , course_id = course_id ) obj_invoice = obj_invoice . invoice except CourseRegistrationCodeInvoiceItem . DoesNotExist : return HttpResponseNotFound ( _ ( "Invoice number '{num}' does not exist." ) . format ( num = invoice_number ) ) if ( event_type == 'invalidate' ) : return invalidate_invoice ( obj_invoice ) else : return re_validate_invoice ( obj_invoice )
this method either invalidate or re validate the sale against the invoice number depending upon the event type .