def test_get_total_amount_of_no_invoices(self): """ Test to check the Invoice Transactions amount. """ total_amount_paid = InvoiceTransaction.get_total_amount_of_paid_course_invoices( self.course_key) self.assertEqual(float(total_amount_paid), 0)
def test_student_used_invoice_paid_enrollment_code_for_course_enrollment(self): """ test to check the user enrollment source and payment status in the enrollment detailed report """ student = UserFactory() self.client.login(username=student.username, password='******') invoice_transaction = InvoiceTransaction( invoice=self.sale_invoice_1, amount=self.sale_invoice_1.total_amount, status='completed', created_by=self.instructor, last_modified_by=self.instructor ) invoice_transaction.save() course_registration_code = CourseRegistrationCode( code='abcde', course_id=self.course.id.to_deprecated_string(), created_by=self.instructor, invoice=self.sale_invoice_1, invoice_item=self.invoice_item, mode_slug='honor' ) course_registration_code.save() redeem_url = reverse('register_code_redemption', args=['abcde']) response = self.client.get(redeem_url) self.assertEquals(response.status_code, 200) # check button text self.assertTrue('Activate Course Enrollment' in response.content) response = self.client.post(redeem_url) self.assertEquals(response.status_code, 200) task_input = {'features': []} with patch('instructor_task.tasks_helper._get_current_task'): result = upload_enrollment_report(None, None, self.course.id, task_input, 'generating_enrollment_report') self.assertDictContainsSubset({'attempted': 1, 'succeeded': 1, 'failed': 0}, result) self._verify_cell_data_in_csv(student.username, 'Enrollment Source', 'Used Registration Code') self._verify_cell_data_in_csv(student.username, 'Payment Status', 'Invoice Paid')
def test_get_total_amount_of_paid_invoices(self): """ Test to check the Invoice Transactions amount. """ InvoiceTransaction.objects.create(invoice=self.invoice, amount='123.45', currency='usd', comments='test comments', status='completed', created_by=self.user, last_modified_by=self.user) total_amount_paid = InvoiceTransaction.get_total_amount_of_paid_course_invoices( self.course_key) self.assertEqual(float(total_amount_paid), 123.45)
def _get_invoice_data(self, registration_code_redemption): """ Returns the Invoice data """ registration_code = registration_code_redemption.registration_code list_price = registration_code.invoice_item.unit_price total_amount = registration_code_redemption.registration_code.invoice.total_amount qty = registration_code_redemption.registration_code.invoice_item.qty payment_amount = total_amount / qty invoice_transaction = InvoiceTransaction.get_invoice_transaction( invoice_id=registration_code_redemption.registration_code.invoice.id) if invoice_transaction is not None: # amount greater than 0 is invoice has bee paid if invoice_transaction.amount > 0: payment_status = 'Invoice Paid' else: # amount less than 0 is invoice has been refunded payment_status = 'Refunded' else: payment_status = 'Invoice Outstanding' transaction_reference_number = registration_code_redemption.registration_code.invoice_id return list_price, payment_amount, payment_status, transaction_reference_number
def get_executive_report(course_id): """ Returns dict containing information about the course executive summary. """ single_purchase_total = PaidCourseRegistration.get_total_amount_of_purchased_item(course_id) bulk_purchase_total = CourseRegCodeItem.get_total_amount_of_purchased_item(course_id) paid_invoices_total = InvoiceTransaction.get_total_amount_of_paid_course_invoices(course_id) gross_paid_revenue = single_purchase_total + bulk_purchase_total + paid_invoices_total all_invoices_total = Invoice.get_invoice_total_amount_for_course(course_id) gross_pending_revenue = all_invoices_total - float(paid_invoices_total) gross_revenue = float(gross_paid_revenue) + float(gross_pending_revenue) refunded_self_purchased_seats = PaidCourseRegistration.get_self_purchased_seat_count( course_id, status='refunded' ) refunded_bulk_purchased_seats = CourseRegCodeItem.get_bulk_purchased_seat_count( course_id, status='refunded' ) total_seats_refunded = refunded_self_purchased_seats + refunded_bulk_purchased_seats self_purchased_refunds = PaidCourseRegistration.get_total_amount_of_purchased_item( course_id, status='refunded' ) bulk_purchase_refunds = CourseRegCodeItem.get_total_amount_of_purchased_item(course_id, status='refunded') total_amount_refunded = self_purchased_refunds + bulk_purchase_refunds top_discounted_codes = CouponRedemption.get_top_discount_codes_used(course_id) total_coupon_codes_purchases = CouponRedemption.get_total_coupon_code_purchases(course_id) bulk_purchased_codes = CourseRegistrationCode.order_generated_registration_codes(course_id) unused_registration_codes = 0 for registration_code in bulk_purchased_codes: if not RegistrationCodeRedemption.is_registration_code_redeemed(registration_code.code): unused_registration_codes += 1 self_purchased_seat_count = PaidCourseRegistration.get_self_purchased_seat_count(course_id) bulk_purchased_seat_count = CourseRegCodeItem.get_bulk_purchased_seat_count(course_id) total_invoiced_seats = CourseRegistrationCode.invoice_generated_registration_codes(course_id).count() total_seats = self_purchased_seat_count + bulk_purchased_seat_count + total_invoiced_seats self_purchases_percentage = 0.0 bulk_purchases_percentage = 0.0 invoice_purchases_percentage = 0.0 avg_price_paid = 0.0 if total_seats != 0: self_purchases_percentage = (float(self_purchased_seat_count) / float(total_seats)) * 100 bulk_purchases_percentage = (float(bulk_purchased_seat_count) / float(total_seats)) * 100 invoice_purchases_percentage = (float(total_invoiced_seats) / float(total_seats)) * 100 avg_price_paid = gross_revenue / total_seats course = get_course_by_id(course_id, depth=0) currency = settings.PAID_COURSE_REGISTRATION_CURRENCY[1] return { 'display_name': course.display_name, 'start_date': course.start.strftime("%Y-%m-%d") if course.start is not None else 'N/A', 'end_date': course.end.strftime("%Y-%m-%d") if course.end is not None else 'N/A', 'total_seats': total_seats, 'currency': currency, 'gross_revenue': float(gross_revenue), 'gross_paid_revenue': float(gross_paid_revenue), 'gross_pending_revenue': gross_pending_revenue, 'total_seats_refunded': total_seats_refunded, 'total_amount_refunded': float(total_amount_refunded), 'average_paid_price': float(avg_price_paid), 'discount_codes_data': top_discounted_codes, 'total_seats_using_discount_codes': total_coupon_codes_purchases, 'total_self_purchase_seats': self_purchased_seat_count, 'total_bulk_purchase_seats': bulk_purchased_seat_count, 'total_invoiced_seats': total_invoiced_seats, 'unused_bulk_purchase_code_count': unused_registration_codes, 'self_purchases_percentage': self_purchases_percentage, 'bulk_purchases_percentage': bulk_purchases_percentage, 'invoice_purchases_percentage': invoice_purchases_percentage, }
def get_executive_report(course_id): """ Returns dict containing information about the course executive summary. """ single_purchase_total = PaidCourseRegistration.get_total_amount_of_purchased_item( course_id) bulk_purchase_total = CourseRegCodeItem.get_total_amount_of_purchased_item( course_id) paid_invoices_total = InvoiceTransaction.get_total_amount_of_paid_course_invoices( course_id) gross_paid_revenue = single_purchase_total + bulk_purchase_total + paid_invoices_total all_invoices_total = Invoice.get_invoice_total_amount_for_course(course_id) gross_pending_revenue = all_invoices_total - float(paid_invoices_total) gross_revenue = float(gross_paid_revenue) + float(gross_pending_revenue) refunded_self_purchased_seats = PaidCourseRegistration.get_self_purchased_seat_count( course_id, status='refunded') refunded_bulk_purchased_seats = CourseRegCodeItem.get_bulk_purchased_seat_count( course_id, status='refunded') total_seats_refunded = refunded_self_purchased_seats + refunded_bulk_purchased_seats self_purchased_refunds = PaidCourseRegistration.get_total_amount_of_purchased_item( course_id, status='refunded') bulk_purchase_refunds = CourseRegCodeItem.get_total_amount_of_purchased_item( course_id, status='refunded') total_amount_refunded = self_purchased_refunds + bulk_purchase_refunds top_discounted_codes = CouponRedemption.get_top_discount_codes_used( course_id) total_coupon_codes_purchases = CouponRedemption.get_total_coupon_code_purchases( course_id) bulk_purchased_codes = CourseRegistrationCode.order_generated_registration_codes( course_id) unused_registration_codes = 0 for registration_code in bulk_purchased_codes: if not RegistrationCodeRedemption.is_registration_code_redeemed( registration_code.code): unused_registration_codes += 1 self_purchased_seat_count = PaidCourseRegistration.get_self_purchased_seat_count( course_id) bulk_purchased_seat_count = CourseRegCodeItem.get_bulk_purchased_seat_count( course_id) total_invoiced_seats = CourseRegistrationCode.invoice_generated_registration_codes( course_id).count() total_seats = self_purchased_seat_count + bulk_purchased_seat_count + total_invoiced_seats self_purchases_percentage = 0.0 bulk_purchases_percentage = 0.0 invoice_purchases_percentage = 0.0 avg_price_paid = 0.0 if total_seats != 0: self_purchases_percentage = (float(self_purchased_seat_count) / float(total_seats)) * 100 bulk_purchases_percentage = (float(bulk_purchased_seat_count) / float(total_seats)) * 100 invoice_purchases_percentage = (float(total_invoiced_seats) / float(total_seats)) * 100 avg_price_paid = gross_revenue / total_seats course = get_course_by_id(course_id, depth=0) currency = settings.PAID_COURSE_REGISTRATION_CURRENCY[1] return { 'display_name': course.display_name, 'start_date': course.start.strftime("%Y-%m-%d") if course.start is not None else 'N/A', 'end_date': course.end.strftime("%Y-%m-%d") if course.end is not None else 'N/A', 'total_seats': total_seats, 'currency': currency, 'gross_revenue': float(gross_revenue), 'gross_paid_revenue': float(gross_paid_revenue), 'gross_pending_revenue': gross_pending_revenue, 'total_seats_refunded': total_seats_refunded, 'total_amount_refunded': float(total_amount_refunded), 'average_paid_price': float(avg_price_paid), 'discount_codes_data': top_discounted_codes, 'total_seats_using_discount_codes': total_coupon_codes_purchases, 'total_self_purchase_seats': self_purchased_seat_count, 'total_bulk_purchase_seats': bulk_purchased_seat_count, 'total_invoiced_seats': total_invoiced_seats, 'unused_bulk_purchase_code_count': unused_registration_codes, 'self_purchases_percentage': self_purchases_percentage, 'bulk_purchases_percentage': bulk_purchases_percentage, 'invoice_purchases_percentage': invoice_purchases_percentage, }