Exemple #1
0
  def SetupYearRecForIncomeTax(
      self, earnings=0, oas=0, gis=0, cpp=0, ei=0,
      rrsp=0, bridging=0,nonreg=0, gains=0, eoy_gains=0,
      unapplied_losses=0, rrsp_contributions=0,
      age=30, retired=False, cpi=1):
    """Set up a person and a year record in one go for testing income tax."""
    j_canuck = person.Person(strategy=self.default_strategy)
    j_canuck.capital_loss_carry_forward = unapplied_losses
    j_canuck.age += age - world.START_AGE
    j_canuck.year += age - world.START_AGE
    j_canuck.retired = retired

    year_rec = utils.YearRecord()
    year_rec.is_retired = j_canuck.retired
    year_rec.year = j_canuck.year
    year_rec.incomes.append(incomes.IncomeReceipt(earnings, incomes.INCOME_TYPE_EARNINGS))
    year_rec.incomes.append(incomes.IncomeReceipt(oas, incomes.INCOME_TYPE_OAS))
    year_rec.incomes.append(incomes.IncomeReceipt(gis, incomes.INCOME_TYPE_GIS))
    year_rec.incomes.append(incomes.IncomeReceipt(cpp, incomes.INCOME_TYPE_CPP))
    year_rec.incomes.append(incomes.IncomeReceipt(ei, incomes.INCOME_TYPE_EI))
    year_rec.withdrawals.append(funds.WithdrawReceipt(nonreg, gains, funds.FUND_TYPE_NONREG))
    year_rec.withdrawals.append(funds.WithdrawReceipt(rrsp, 0, funds.FUND_TYPE_RRSP))
    year_rec.withdrawals.append(funds.WithdrawReceipt(bridging, 0, funds.FUND_TYPE_BRIDGING))
    year_rec.tax_receipts.append(funds.TaxReceipt(eoy_gains, funds.FUND_TYPE_NONREG))
    year_rec.deposits.append(funds.DepositReceipt(rrsp_contributions, funds.FUND_TYPE_RRSP))
    year_rec.cpi = cpi

    year_rec = j_canuck.CalcPayrollDeductions(year_rec)

    return (j_canuck, year_rec)
Exemple #2
0
 def testGISCalcIncomeBaseIncomes(self):
     income = incomes.GIS()
     income.last_year_income_base = 10000
     year_rec = utils.YearRecord()
     year_rec.incomes = [
         incomes.IncomeReceipt(1000, incomes.INCOME_TYPE_EARNINGS),
         incomes.IncomeReceipt(2000, incomes.INCOME_TYPE_CPP),
         incomes.IncomeReceipt(3000, incomes.INCOME_TYPE_EI),
         incomes.IncomeReceipt(4000, incomes.INCOME_TYPE_OAS)
     ]
     year_rec.ei_premium = 0
     year_rec.cpp_contribution = 0
     self.assertEqual(income._CalcIncomeBase(year_rec), 6000)
Exemple #3
0
 def testGiveMeMoney(self):
     income = incomes.Income()
     amount, taxable, year_rec = income.GiveMeMoney(utils.YearRecord())
     self.assertEqual(amount, 0)
     self.assertEqual(taxable, True)
     self.assertIn(incomes.IncomeReceipt(0, incomes.INCOME_TYPE_NONE),
                   year_rec.incomes)
Exemple #4
0
 def testEarningsUnemployed(self):
     income = incomes.Earnings()
     amount, taxable, year_rec = income.GiveMeMoney(utils.YearRecord())
     self.assertEqual(amount, 0)
     self.assertEqual(taxable, True)
     self.assertIn(incomes.IncomeReceipt(0, incomes.INCOME_TYPE_EARNINGS),
                   year_rec.incomes)
Exemple #5
0
    def setUpYearRecForGIS(self, income_base=0, cpi=1, has_oas=True):
        year_rec = utils.YearRecord()
        year_rec.cpi = cpi
        year_rec.incomes = []
        if has_oas:
            year_rec.incomes.append(
                incomes.IncomeReceipt(world.OAS_BENEFIT,
                                      incomes.INCOME_TYPE_OAS))

        # We want to force some values for the current year's income base
        year_rec.ei_premium = 0
        year_rec.cpp_contribution = 0
        year_rec.incomes.append(
            incomes.IncomeReceipt(income_base, incomes.INCOME_TYPE_EARNINGS))

        return year_rec
Exemple #6
0
 def testCPPDuringWorkingPeriod(self):
     income = incomes.CPP()
     amount, taxable, year_rec = income.GiveMeMoney(utils.YearRecord())
     self.assertEqual(amount, 0)
     self.assertEqual(taxable, True)
     self.assertIn(incomes.IncomeReceipt(0, incomes.INCOME_TYPE_CPP),
                   year_rec.incomes)
Exemple #7
0
 def testRRSPRoomLimit(self):
   fund = funds.RRSP()
   year_rec = utils.YearRecord()
   year_rec.incomes.append(incomes.IncomeReceipt(140000, incomes.INCOME_TYPE_EARNINGS))
   self.assertEqual(fund.room, world.RRSP_INITIAL_LIMIT)
   fund.Update(year_rec)
   self.assertEqual(fund.room, world.RRSP_INITIAL_LIMIT+world.RRSP_LIMIT)
Exemple #8
0
 def testGISBenefitPositiveIncomeNoOAS(self):
     income = incomes.GIS()
     income.last_year_income_base = 1000
     year_rec = self.setUpYearRecForGIS(has_oas=False, income_base=1000)
     amount, taxable, year_rec = income.GiveMeMoney(year_rec)
     self.assertEqual(amount, 0)
     self.assertFalse(taxable)
     self.assertIn(incomes.IncomeReceipt(0, incomes.INCOME_TYPE_GIS),
                   year_rec.incomes)
Exemple #9
0
 def testOASBeforeRetirement(self):
     income = incomes.OAS()
     year_rec = utils.YearRecord()
     year_rec.age = 60
     amount, taxable, year_rec = income.GiveMeMoney(year_rec)
     self.assertEqual(amount, 0)
     self.assertEqual(taxable, True)
     self.assertIn(incomes.IncomeReceipt(0, incomes.INCOME_TYPE_OAS),
                   year_rec.incomes)
Exemple #10
0
 def testGISCalcIncomeBaseIncomesAndPayrollDeductions(self):
     income = incomes.GIS()
     income.last_year_income_base = 10000
     year_rec = utils.YearRecord()
     year_rec.incomes = [
         incomes.IncomeReceipt(5000, incomes.INCOME_TYPE_EARNINGS)
     ]
     year_rec.ei_premium = 2000
     year_rec.cpp_contribution = 2000
     self.assertEqual(income._CalcIncomeBase(year_rec), 1000)
Exemple #11
0
 def testOASAfterRetirement(self):
     income = incomes.OAS()
     year_rec = utils.YearRecord()
     year_rec.age = 70
     amount, taxable, year_rec = income.GiveMeMoney(year_rec)
     self.assertEqual(amount, world.OAS_BENEFIT)
     self.assertEqual(taxable, True)
     self.assertIn(
         incomes.IncomeReceipt(world.OAS_BENEFIT, incomes.INCOME_TYPE_OAS),
         year_rec.incomes)
Exemple #12
0
 def testRRSPUpdate(self):
   fund = funds.RRSP()
   fund.amount = 20
   year_rec = utils.YearRecord()
   year_rec.growth_rate = 0.2
   year_rec.inflation = 1
   year_rec.incomes.append(incomes.IncomeReceipt(10000, incomes.INCOME_TYPE_EARNINGS))
   fund.Update(year_rec)
   self.assertEqual(fund.amount, 48)
   self.assertEqual(fund.unrealized_gains, 0)
Exemple #13
0
 def testGISCalcIncomeBaseUsesLesserIncome(self):
     income = incomes.GIS()
     income.last_year_income_base = 5000
     year_rec = utils.YearRecord()
     year_rec.incomes = [
         incomes.IncomeReceipt(8000, incomes.INCOME_TYPE_EARNINGS)
     ]
     year_rec.ei_premium = 0
     year_rec.cpp_contribution = 0
     self.assertEqual(income._CalcIncomeBase(year_rec), 5000)
     self.assertEqual(income.last_year_income_base, 8000)
Exemple #14
0
 def testEarningsEmployedNegativeRandom(self):
     income = incomes.Earnings()
     year_rec = utils.YearRecord()
     year_rec.is_employed = True
     with unittest.mock.patch('random.normalvariate') as my_random:
         my_random.return_value = -10000
         amount, taxable, year_rec = income.GiveMeMoney(year_rec)
         self.assertEqual(amount, 0)
         self.assertEqual(taxable, True)
         self.assertIn(
             incomes.IncomeReceipt(0, incomes.INCOME_TYPE_EARNINGS),
             year_rec.incomes)
Exemple #15
0
 def testEIBenefitsUnemployedInsuredRetired(self):
     income = incomes.EI()
     last_year_rec = utils.YearRecord()
     last_year_rec.is_employed = True
     last_year_rec.insurable_earnings = 100
     this_year_rec = utils.YearRecord()
     this_year_rec.is_employed = False
     this_year_rec.is_retired = True
     income.AnnualUpdate(last_year_rec)
     amount, taxable, year_rec = income.GiveMeMoney(this_year_rec)
     self.assertEqual(amount, 0)
     self.assertEqual(taxable, True)
     self.assertIn(incomes.IncomeReceipt(0, incomes.INCOME_TYPE_EI),
                   year_rec.incomes)