def _get_discount_prices(user, course, assume_discount=False): """ Return a tuple of (original, discounted, percentage) If assume_discount is True, we do not check if a discount applies and just go ahead with discount math anyway. Each returned price is a string with appropriate currency formatting added already. discounted and percentage will be returned as None if no discount is applicable. """ base_price = get_course_prices(course, verified_only=True)[0] can_discount = assume_discount or can_receive_discount(user, course) if can_discount: percentage = discount_percentage(course) discounted_price = base_price * ((100.0 - percentage) / 100) if discounted_price: # leave 0 prices alone, as format_course_price below will adjust to 'Free' if discounted_price == int(discounted_price): discounted_price = f'{discounted_price:0.0f}' else: discounted_price = f'{discounted_price:0.2f}' return format_course_price(base_price), format_course_price( discounted_price), percentage else: return format_course_price(base_price), None, None
def get_program_price_and_skus(courses): """ Get the total program price and purchase skus from these courses in the program """ program_price = 0 skus = [] for course in courses: course_price, course_sku = get_course_entitlement_price_and_sku(course) if course_price is not None and course_sku is not None: program_price = Decimal(program_price) + Decimal(course_price) skus.append(course_sku) if program_price <= 0: program_price = None skus = None else: program_price = format_course_price(program_price) program_price = six.text_type(program_price) return program_price, skus