def test_isEntitled_is_not_entitled(self):
     spousal_insurance_benefit = SpousalInsuranceBenefit.objects.get(
         start_date__lte=date(2016, 1, 1), end_date__gte=date(2016, 12, 31))
     primary_insurance_amount = Money(amount=1000)
     spousal_primary_insurance_amount = Money(amount=1829)
     self.assertFalse(
         spousal_insurance_benefit.isEntitled(
             primary_insurance_amount, spousal_primary_insurance_amount))
 def test_calculate_is_not_entitled(self):
     spousal_insurance_benefit = SpousalInsuranceBenefit.objects.get(
         start_date__lte=date(2016, 1, 1), end_date__gte=date(2016, 12, 31))
     self.assertAlmostEqual(
         0,
         spousal_insurance_benefit.calculate(
             primary_insurance_amount=Money(amount=411),
             spousal_primary_insurance_amount=Money(amount=1829),
             government_pension_offset=Money(amount=1064)))
 def test_calculate(self):
     years_of_non_covered_earnings = 25
     wep = WindfallEliminationProvision.objects.get(
         start_date__lte=date(2016, 1, 1), end_date__gte=date(2016, 12, 31))
     self.assertAlmostEqual(
         427.80,
         wep.calculate(primary_insurance_amount=Money(amount=839),
                       wep_primary_insurance_amount=Money(amount=411.20),
                       monthly_non_covered_pension=Money(amount=1595.24)))
Example #4
0
 def test_calculate_without_max_survivor_benefit_reduction(self):
     survivor_insurance_benefit = SurvivorInsuranceBenefit.objects.get(
         Q(start_date__lte=date(2016, 1, 1))
         & Q(end_date__gte=date(2016, 12, 31)))
     self.assertAlmostEqual(
         354.00,
         survivor_insurance_benefit.calculate(
             primary_insurance_amount=Money(amount=411),
             deceased_spousal_primary_insurance_amount=Money(amount=1829),
             survivor_early_retirement_reduction_factor=0,
             spousal_delay_retirement_factor=0,
             government_pension_offset=Money(amount=1064)))
    def test_stepByStep_is_not_entitled(self):
        spousal_insurance_benefit = SpousalInsuranceBenefit.objects.get(
            start_date__lte=date(2016, 1, 1), end_date__gte=date(2016, 12, 31))

        expected_task = Task.objects.create()
        instruction = expected_task.instruction_set.create(
            description='Get spousal\' primary insurance amount', order=1)
        instruction.expression_set.create(
            description='spousal\'s primary insurance amount = $1,829.00',
            order=1)
        instruction = expected_task.instruction_set.create(
            description=
            'Calculate the maximum entitlement to spousal insurance benefit',
            order=2)
        instruction.expression_set.create(
            description=
            'maximum benefit entitlement = spousal\'s primary insurance amount x maximum benefit entitlement factor',
            order=1)
        instruction.expression_set.create(
            description='maximum benefit entitlement = $1,829.00 x 1/2',
            order=2)
        instruction.expression_set.create(
            description='maximum benefit entitlement = $914.50', order=3)
        instruction = expected_task.instruction_set.create(
            description='Get primary insurance amount', order=3)
        instruction.expression_set.create(
            description='primary insurance amount = $1,000.00', order=1)
        instruction = expected_task.instruction_set.create(
            description=
            'Determine if person is entitled to spousal insurance benefit',
            order=4)
        instruction.expression_set.create(
            description=
            'primary insurance amount < maximum benefit entitlement?',
            order=1)
        instruction.expression_set.create(description='$1,000.00 < $914.50?',
                                          order=2)
        instruction.expression_set.create(description='False', order=3)
        instruction = expected_task.instruction_set.create(
            description='Set spousal insurance benefit to zero', order=5)
        instruction.expression_set.create(
            description='spousal insurance benefit = $0.00', order=1)

        self.assertEqual(
            expected_task,
            spousal_insurance_benefit.stepByStep(
                primary_insurance_amount=Money(amount=1000),
                spousal_primary_insurance_amount=Money(amount=1829),
                government_pension_offset=Money(amount=213)))
    def test_stepByStep(self):
        years_of_non_covered_earnings = 25
        wep = WindfallEliminationProvision.objects.get(
            start_date__lte=date(2016, 1, 1), end_date__gte=date(2016, 12, 31))

        expected_task = Task.objects.create()
        instruction = expected_task.instruction_set.create(
            description="Get WEP's primary insurance amount", order=1)
        instruction.expression_set.create(
            description=
            "WEP's primary insurance amount = primary insurance amount",
            order=1)
        instruction.expression_set.create(
            description="WEP's primary insurance amount = $411.20", order=2)

        instruction = expected_task.instruction_set.create(
            description="Get monthly non covered pension", order=2)
        instruction.expression_set.create(
            description="monthly non covered pension = $1,595.24", order=1)

        instruction = expected_task.instruction_set.create(
            description="Get primary insurance amount", order=3)
        instruction.expression_set.create(
            description="primary insurance amount = $839.00", order=1)

        instruction = expected_task.instruction_set.create(
            description='Find Windfall Elimination Provision reduction',
            order=4)
        instruction.expression_set.create(
            description=
            'WEP reduction = min(monthly non covered pension x 1/2, max(primary insurance amount - WEP\'s primary insurance amount, 0))',
            order=1)
        instruction.expression_set.create(
            description=
            'WEP reduction = min($1,595.24 x 1/2, max($839.00 - $411.20, 0))',
            order=2)
        instruction.expression_set.create(
            description='WEP reduction = min($797.62, max($427.80, 0)',
            order=3)
        instruction.expression_set.create(
            description='WEP reduction = min($797.62, $427.80)', order=4)
        instruction.expression_set.create(
            description='WEP reduction = $427.80', order=5)

        self.assertEqual(
            expected_task,
            wep.stepByStep(primary_insurance_amount=Money(amount=839),
                           wep_primary_insurance_amount=Money(amount=411.20),
                           monthly_non_covered_pension=Money(amount=1595.24)))
Example #7
0
    def test_stepByStep(self):
        gpo = GovernmentPensionOffset.objects.get(
            start_date__lte=date(2016, 1, 1), end_date__gte=date(2016, 12, 31))

        expected_task = Task.objects.create()
        instruction = expected_task.instruction_set.create(
            description='Get monthly non covered pension', order=1)
        instruction.expression_set.create(
            description='monthly non covered pension = $600.00', order=1)
        instruction = expected_task.instruction_set.create(
            description='Get offset', order=2)
        instruction.expression_set.create(description='offset = 2/3', order=1)
        instruction = expected_task.instruction_set.create(
            description=
            'Multiply the monthly non covered pension with the offset',
            order=3)
        instruction.expression_set.create(
            description=
            'government pension offset = monthly non covered pension x offset',
            order=1)
        instruction.expression_set.create(
            description='government pension offset = $600.00 x 2/3', order=2)
        instruction.expression_set.create(
            description='government pension offset = $400.00', order=3)

        self.assertEqual(
            expected_task,
            gpo.stepByStep(monthly_non_covered_pension=Money(amount=600)))
 def test_maxEntitlement(self):
     spousal_insurance_benefit = SpousalInsuranceBenefit.objects.get(
         start_date__lte=date(2016, 1, 1), end_date__gte=date(2016, 12, 31))
     spousal_primary_insurance_amount = Money(amount=1829)
     self.assertAlmostEqual(
         914.5,
         spousal_insurance_benefit.maxEntitlement(
             spousal_primary_insurance_amount))
	def stepByStep(self, request, pk=None):
		serializer = MoneySerializer(data=request.data)
		if serializer.is_valid():
			monthly_non_covered_pension = Money(**serializer.validated_data)
			
			gpo_rule = self.get_object()
			gpo_task = gpo_rule.stepByStep(monthly_non_covered_pension=monthly_non_covered_pension)

			gpo_serializer = TaskSerializer(gpo_task)
			return Response(gpo_serializer.data, content_type='application/json;charset=utf-8')
	def calculate(self, request, pk=None):
		serializer = MoneySerializer(data=request.data)
		if serializer.is_valid():
			monthly_non_covered_pension = Money(**serializer.validated_data)

			gpo_rule = self.get_object()
			gpo = gpo_rule.calculate(monthly_non_covered_pension=monthly_non_covered_pension)

			gpo_serializer = MoneySerializer(gpo)
			return Response(gpo_serializer.data, content_type='application/json;charset=utf-8')
		else:
			return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
	def test_stepByStep(self):
		pia = PrimaryInsuranceAmount.objects.get(
			start_date__lte=date(2016, 1, 1), 
			end_date__gte=date(2016, 12, 31),
			type_of_primary_insurance_formula=PrimaryInsuranceAmount.BASIC
		)
		first_pia_factor = max(0, 0 + 0.9 * ( min(1071, 856) - 0 ))
		second_pia_factor = max(0, 0.32 * ( min(1071, 5157) - 856 ))
		third_pia_factor = max(0, 0.15 * ( min(1071, 0) - 5157 ))

		expected_task = Task.objects.create()
		instruction = expected_task.instruction_set.create(description='Get average indexed monthly earning', order=1)
		instruction.expression_set.create(description='average indexed monthly earning = $1,071.00', order=1)
		instruction = expected_task.instruction_set.create(description='Initalize total primary insurance amount to 0', order=2)
		instruction.expression_set.create(description='primary insurance amount = $0.00', order=1)
		instruction = expected_task.instruction_set.create(description='Add 90.0 percent his/her average indexed monthly ' \
			'earning up to $856.00 to total primary insurance amount', order=3)
		instruction.expression_set.create(description='primary insurance amount = primary insurance amount + ' \
			'max($0.00, factor x ( min(average indexed monthly earning, minimum dollar amount threshold) - maximum dollar amount threshold ))', order=1)
		instruction.expression_set.create(description='primary insurance amount = max($0.00, $0.00 + 0.9 x ( min($1,071.00, $856.00) - $0.00 ))', order=2)
		instruction.expression_set.create(description='primary insurance amount = $770.40', order=3),
		instruction = expected_task.instruction_set.create(description='Add 32.0 percent his/her average indexed monthly ' \
			'earning between $856.00 and $5,157.00 to total primary insurance amount', order=4)
		instruction.expression_set.create(description='primary insurance amount = primary insurance amount + ' \
			'max($0.00, factor x ( min(average indexed monthly earning, minimum dollar amount threshold) - maximum dollar amount threshold ))', order=1)
		instruction.expression_set.create(description='primary insurance amount = max($0.00, $770.40 + 0.32 x ' \
			'( min($1,071.00, $5,157.00) - $856.00 ))', order=2)
		instruction.expression_set.create(description='primary insurance amount = $839.20', order=3),
		instruction = expected_task.instruction_set.create(description='Add 15.0 percent his/her average indexed monthly ' \
			'earning above $5,157.00 to total primary insurance amount', order=5)
		instruction.expression_set.create(description='primary insurance amount = primary insurance amount + ' \
			'max($0.00, factor x ( min(average indexed monthly earning, minimum dollar amount threshold) - maximum dollar amount threshold ))', order=1)
		instruction.expression_set.create(description='primary insurance amount = max($0.00, $839.20 + ' \
			'0.15 x ( min($1,071.00, $0.00) - $5,157.00 ))', order=2)
		instruction.expression_set.create(description='primary insurance amount = $839.20', order=3),
		instruction = expected_task.instruction_set.create(description='Round total primary insurance amount to the next lower multiple of $0.10 ' \
			'if it is not already a multiple of $0.10', order=6)
		instruction.expression_set.create(description='primary insurance amount = floor(primary insurance amount * 10) / 10', order=1)
		instruction.expression_set.create(description='primary insurance amount = floor($839.20 * 10) / 10', order=2)
		instruction.expression_set.create(description='primary insurance amount = $839.20', order=3)
		
		primary_insurance_amount_task = pia.stepByStep(average_indexed_monthly_earning=Money(amount=1071), year_of_coverage=0)
		for expected_instruction in expected_task.instruction_set.all():
			pia_instruction = primary_insurance_amount_task.instruction_set.get(order=expected_instruction.order)
			self.assertEqual(pia_instruction, expected_instruction)

			for expected_expression in expected_instruction.expression_set.all():
				pia_expression = pia_instruction.expression_set.get(order=expected_expression.order)
				self.assertEqual(pia_expression, expected_expression)
Example #12
0
    def test_calculate(self):
        gpo = GovernmentPensionOffset.objects.get(
            start_date__lte=date(2016, 1, 1), end_date__gte=date(2016, 12, 31))

        monthly_non_covered_pension = Money(amount=600)

        client = APIClient()
        url = reverse('benefit-rule:government-pension-offset-calculate',
                      args=[gpo.id])
        serializer = MoneySerializer(monthly_non_covered_pension)
        response = client.post(
            url, {'monthly_non_covered_pension': {
                'amount': 600.00
            }},
            format='json')
        # gpo_rule_calculate_view = GovernmentPensionOffsetViewSet.as_view({'post': 'calculate'})
        # response = gpo_rule_calculate_view(request)

        print(response.data)
        serializer = MoneySerializer(response.data)
        # print(serializer.data)
        # print(gpo.calculate(monthly_non_covered_pension=monthly_non_covered_pension))
        # self.assertEqual(serializer.data, gpo.calculate(monthly_non_covered_pension=monthly_non_covered_pension))
Example #13
0
 def annual_non_covered_earnings(self):
     return [
         Money(amount=self.annual_non_covered_earning.amount)
         for earning in range(self.years_of_non_covered_earnings)
     ]
Example #14
0
 def test_calculate(self):
     gpo = GovernmentPensionOffset.objects.get(
         start_date__lte=date(2016, 1, 1), end_date__gte=date(2016, 12, 31))
     self.assertAlmostEqual(
         600 * 2 / 3,
         gpo.calculate(monthly_non_covered_pension=Money(amount=600)))
    def test_stepByStep_is_entitled(self):
        spousal_insurance_benefit = SpousalInsuranceBenefit.objects.get(
            start_date__lte=date(2016, 1, 1), end_date__gte=date(2016, 12, 31))

        expected_task = Task.objects.create()
        instruction = expected_task.instruction_set.create(
            description='Get spousal\' primary insurance amount', order=1)
        instruction.expression_set.create(
            description='spousal\'s primary insurance amount = $1,829.00',
            order=1)

        instruction = expected_task.instruction_set.create(
            description=
            'Calculate the maximum entitlement to spousal insurance benefit',
            order=2)
        instruction.expression_set.create(
            description=
            'maximum benefit entitlement = spousal\'s primary insurance amount x maximum benefit entitlement factor',
            order=1)
        instruction.expression_set.create(
            description='maximum benefit entitlement = $1,829.00 x 1/2',
            order=2)
        instruction.expression_set.create(
            description='maximum benefit entitlement = $914.50', order=3)

        instruction = expected_task.instruction_set.create(
            description='Get primary insurance amount', order=3)
        instruction.expression_set.create(
            description='primary insurance amount = $679.00', order=1)

        instruction = expected_task.instruction_set.create(
            description=
            'Determine if person is entitled to spousal insurance benefit',
            order=4)
        instruction.expression_set.create(
            description=
            'primary insurance amount < maximum benefit entitlement?',
            order=1)
        instruction.expression_set.create(description='$679.00 < $914.50?',
                                          order=2)
        instruction.expression_set.create(description='True', order=3)

        instruction = expected_task.instruction_set.create(
            description=
            'Set spousal insurance benefit to maximum benefit entitlement',
            order=5)
        instruction.expression_set.create(
            description=
            'spousal insurance benefit = maximum benefit entitlement',
            order=1)
        instruction.expression_set.create(
            description='spousal insurance benefit = $914.50', order=2)

        instruction = expected_task.instruction_set.create(
            description=
            'Subtract the primary insurance amount from spousal insurance benefit',
            order=6)
        instruction.expression_set.create(
            description=
            'spousal insurance benefit = spousal insurance benefit - primary insurance amount',
            order=1)
        instruction.expression_set.create(
            description=f'spousal insurance benefit = $914.50 - $679.00',
            order=2)
        instruction.expression_set.create(
            description=f'spousal insurance benefit = $235.50', order=3)

        instruction = expected_task.instruction_set.create(
            description='Get government pension offset', order=7)
        instruction.expression_set.create(
            description=f'government pension offset = $213.00', order=1)

        instruction = expected_task.instruction_set.create(
            description=
            'Subtract the government pension offset from spousal insurance benefit',
            order=8)
        instruction.expression_set.create(
            description=
            'spousal insurance benefit = spousal insurance benefit - government pension offset',
            order=1)
        instruction.expression_set.create(
            description=f'spousal insurance benefit = $235.50 - $213.00',
            order=2)
        instruction.expression_set.create(
            description=f'spousal insurance benefit = $22.50', order=3)

        instruction = expected_task.instruction_set.create(
            description='Cap spousal insurance benefit', order=9)
        instruction.expression_set.create(
            description=
            'spousal insurance benefit = max($0.00, spousal insurance benefit)',
            order=1)
        instruction.expression_set.create(
            description='spousal insurance benefit = max($0.00, $22.50)',
            order=2)
        instruction.expression_set.create(
            description='spousal insurance benefit = $22.50', order=3)

        self.assertEqual(
            expected_task,
            spousal_insurance_benefit.stepByStep(
                primary_insurance_amount=Money(amount=679),
                spousal_primary_insurance_amount=Money(amount=1829),
                government_pension_offset=Money(amount=213)))