def get_cost_info(request): validate_request( request, ["GET"], ["start_date", "n_subjects", "registration_discount"] ) start_date = parse_start_date_or_error(request) n_subjects = parse_n_subjects_or_error(request) registration_discount = Decimal(request.GET["registration_discount"]) registration_base_cost = models.RegistrationCost.get_cost_for(start_date) registration_cost = float( (100 - registration_discount) * registration_base_cost / 100 ) monthly_cost = models.MonthlyCost.get_cost_for(start_date) response = { "monthly_cost": monthly_cost, "registration_cost": registration_cost, "prorated_cost": utils.prorated_cost(start_date, monthly_cost), "total_cost": utils.total_cost( start_date, monthly_cost, registration_cost, n_subjects ), } return JsonResponse(response)
def prorated_first_month_cost(self): """ Returns the prorated cost for the first month. The prorated cost is defined relative to the starting date as such: floor((PDL / TPD) * C) where PDL = Primary Days Left in Month TPD = Total Primary Days in Month C = Monthly Cost TODO: I bet that enum refactor will make this nicer """ return utils.prorated_cost(self.start_date, self.monthly_cost)
def test_prorated_cost_ex4(): start_date = date(2017, 10, 7) monthly_cost = 115 assert 102 == utils.prorated_cost(start_date, monthly_cost)
def test_prorated_cost_ex3(): start_date = date(2017, 11, 28) monthly_cost = 115 assert 14 == utils.prorated_cost(start_date, monthly_cost)
def test_prorated_cost_ex2(): start_date = date(2017, 12, 12) monthly_cost = 115 assert 77 == utils.prorated_cost(start_date, monthly_cost)
def test_prorated_cost_ex1(): start_date = date(2017, 11, 11) monthly_cost = 115 assert 86 == utils.prorated_cost(start_date, monthly_cost)