def test_sale_order_features_without_discount(self): """ Test Order Sales Report CSV """ query_features = [ ('id', 'Order Id'), ('company_name', 'Company Name'), ('company_contact_name', 'Company Contact Name'), ('company_contact_email', 'Company Contact Email'), ('total_amount', 'Total Amount'), ('total_codes', 'Total Codes'), ('total_used_codes', 'Total Used Codes'), ('logged_in_username', 'Login Username'), ('logged_in_email', 'Login User Email'), ('purchase_time', 'Date of Sale'), ('customer_reference_number', 'Customer Reference Number'), ('recipient_name', 'Recipient Name'), ('recipient_email', 'Recipient Email'), ('bill_to_street1', 'Street 1'), ('bill_to_street2', 'Street 2'), ('bill_to_city', 'City'), ('bill_to_state', 'State'), ('bill_to_postalcode', 'Postal Code'), ('bill_to_country', 'Country'), ('order_type', 'Order Type'), ('status', 'Order Item Status'), ('coupon_code', 'Coupon Code'), ('unit_cost', 'Unit Price'), ('list_price', 'List Price'), ('codes', 'Registration Codes'), ('course_id', 'Course Id'), ('quantity', 'Quantity'), ('total_discount', 'Total Discount'), ('total_amount', 'Total Amount Paid'), ] # add the coupon code for the course order = Order.get_cart_for_user(self.instructor) order.order_type = 'business' order.save() order.add_billing_details(company_name='Test Company', company_contact_name='Test', company_contact_email='test@123', recipient_name='R1', recipient_email='', customer_reference_number='PO#23') CourseRegCodeItem.add_to_order(order, self.course.id, 4) order.purchase() # get the updated item item = order.orderitem_set.all().select_subclasses()[0] db_columns = [x[0] for x in query_features] sale_order_records_list = sale_order_record_features( self.course.id, db_columns) for sale_order_record in sale_order_records_list: self.assertEqual(sale_order_record['recipient_email'], order.recipient_email) self.assertEqual(sale_order_record['recipient_name'], order.recipient_name) self.assertEqual(sale_order_record['company_name'], order.company_name) self.assertEqual(sale_order_record['company_contact_name'], order.company_contact_name) self.assertEqual(sale_order_record['company_contact_email'], order.company_contact_email) self.assertEqual(sale_order_record['customer_reference_number'], order.customer_reference_number) self.assertEqual(sale_order_record['unit_cost'], item.unit_cost) # Make sure list price is not None and matches the unit price since no discount was applied. self.assertIsNotNone(sale_order_record['list_price']) self.assertEqual(sale_order_record['list_price'], item.unit_cost) self.assertEqual(sale_order_record['status'], item.status) self.assertEqual(sale_order_record['coupon_code'], 'N/A') self.assertEqual(sale_order_record['total_amount'], item.unit_cost * item.qty) self.assertEqual(sale_order_record['total_discount'], 0) self.assertEqual(sale_order_record['quantity'], item.qty)
def test_sale_order_features_with_discount(self): """ Test Order Sales Report CSV """ query_features = [('id', 'Order Id'), ('company_name', 'Company Name'), ('company_contact_name', 'Company Contact Name'), ('company_contact_email', 'Company Contact Email'), ('total_amount', 'Total Amount'), ('total_codes', 'Total Codes'), ('total_used_codes', 'Total Used Codes'), ('logged_in_username', 'Login Username'), ('logged_in_email', 'Login User Email'), ('purchase_time', 'Date of Sale'), ('customer_reference_number', 'Customer Reference Number'), ('recipient_name', 'Recipient Name'), ('recipient_email', 'Recipient Email'), ('bill_to_street1', 'Street 1'), ('bill_to_street2', 'Street 2'), ('bill_to_city', 'City'), ('bill_to_state', 'State'), ('bill_to_postalcode', 'Postal Code'), ('bill_to_country', 'Country'), ('order_type', 'Order Type'), ('status', 'Order Item Status'), ('coupon_code', 'Coupon Code'), ('unit_cost', 'Unit Price'), ('list_price', 'List Price'), ('codes', 'Registration Codes'), ('course_id', 'Course Id')] # add the coupon code for the course coupon = Coupon(code='test_code', description='test_description', course_id=self.course.id, percentage_discount='10', created_by=self.instructor, is_active=True) coupon.save() order = Order.get_cart_for_user(self.instructor) order.order_type = 'business' order.save() order.add_billing_details(company_name='Test Company', company_contact_name='Test', company_contact_email='test@123', recipient_name='R1', recipient_email='', customer_reference_number='PO#23') CourseRegCodeItem.add_to_order(order, self.course.id, 4) # apply the coupon code to the item in the cart resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': coupon.code}) self.assertEqual(resp.status_code, 200) order.purchase() # get the updated item item = order.orderitem_set.all().select_subclasses()[0] # get the redeemed coupon information coupon_redemption = CouponRedemption.objects.select_related( 'coupon').filter(order=order) db_columns = [x[0] for x in query_features] sale_order_records_list = sale_order_record_features( self.course.id, db_columns) for sale_order_record in sale_order_records_list: self.assertEqual(sale_order_record['recipient_email'], order.recipient_email) self.assertEqual(sale_order_record['recipient_name'], order.recipient_name) self.assertEqual(sale_order_record['company_name'], order.company_name) self.assertEqual(sale_order_record['company_contact_name'], order.company_contact_name) self.assertEqual(sale_order_record['company_contact_email'], order.company_contact_email) self.assertEqual(sale_order_record['customer_reference_number'], order.customer_reference_number) self.assertEqual(sale_order_record['unit_cost'], item.unit_cost) self.assertEqual(sale_order_record['list_price'], item.list_price) self.assertEqual(sale_order_record['status'], item.status) self.assertEqual(sale_order_record['coupon_code'], coupon_redemption[0].coupon.code)