Ejemplo n.º 1
0
    def __init__(self, form_data={}):
        super(PropertyPayload, self).__init__()

        def val(field):
            return form_data.get(field)

        def yes(field):
            return form_data.get(field) == YES

        def no(field):
            return form_data.get(field) == NO

        self.update({
            "value":
            to_amount(val("property_value")),
            "mortgage_left":
            to_amount(val("mortgage_remaining")),
            "share":
            100 if no("other_shareholders") else None,
            "disputed":
            val("in_dispute"),
            "rent":
            MoneyInterval(mi("rent_amount", val))
            if yes("is_rented") else MoneyInterval(0),
            "main":
            val("is_main_home"),
        })
Ejemplo n.º 2
0
    def __init__(self, form_data={}):
        super(AdditionalBenefitsPayload, self).__init__()

        def val(field):
            return form_data.get(field)

        def yes(field):
            return form_data[field] == YES

        benefits = val("benefits")

        payload = {
            "on_nass_benefits": nass(benefits),  # always False
            "you": {
                "income": {
                    "benefits":
                    MoneyInterval(mi("total_other_benefit", val))
                    if yes("other_benefits") else MoneyInterval(0)
                }
            },
        }

        if benefits:
            payload["notes"] = u"Other benefits:\n - {0}".format(
                "\n - ".join(benefits))

        self.update(payload)
Ejemplo n.º 3
0
def recursive_update(orig, other):
    for key, val in other.iteritems():

        if key not in orig:
            if isinstance(val, Mapping):
                orig[key] = deepcopy(val)
            else:
                orig[key] = val

        elif orig[key] == val:
            continue

        elif key == "notes" and orig[key] != val:
            orig[key] = "{0}\n\n{1}".format(orig[key], val)

        elif isinstance(val, Mapping):
            if MoneyInterval.is_money_interval(val):
                orig[key] = MoneyInterval(val)
            elif val != {}:
                if not isinstance(orig[key], Mapping):
                    orig[key] = {}
                orig[key] = recursive_update(orig[key], val)
        else:
            orig[key] = val

    return orig
Ejemplo n.º 4
0
 def default(cls):
     return {
         "you": {
             "deductions": {
                 "rent": MoneyInterval(0),
                 "maintenance": MoneyInterval(0),
                 "childcare": MoneyInterval(0),
                 "criminal_legalaid_contributions": 0,
             }
         }
     }
Ejemplo n.º 5
0
 def default(cls):
     return {
         "property_set": [],
         "you": {
             "deductions": {
                 "mortgage": MoneyInterval(0)
             },
             "income": {
                 "other_income": MoneyInterval(0)
             }
         },
     }
Ejemplo n.º 6
0
    def __init__(self, form_data={}):
        super(YourBenefitsPayload, self).__init__()

        def is_selected(ben):
            return ben in form_data["benefits"]

        benefits = {ben: is_selected(ben) for ben in PASSPORTED_BENEFITS}
        is_passported = passported(form_data["benefits"])

        payload = {
            "specific_benefits": benefits,
            "on_passported_benefits": is_passported
        }

        if is_passported:
            payload = recursive_update(payload, IncomePayload.default)
            payload = recursive_update(payload, OutgoingsPayload.default)
        else:

            def val(field):
                return form_data.get(field)

            payload["you"] = {
                "income": {
                    "child_benefits": MoneyInterval(mi("child_benefit", val))
                }
            }

        self.update(payload)
    def test_child_tax_credits_and_working_tax_credits(self):
        update_session("AboutYouForm", is_employed=YES, have_children=YES)

        mt = MeansTest()
        mt.update_from_form(
            "IncomeForm",
            dict(
                flatten({
                    "your_income": {
                        "earnings":
                        post_money_interval("0"),
                        "income_tax":
                        post_money_interval("0"),
                        "national_insurance":
                        post_money_interval("0"),
                        "child_tax_credit":
                        post_money_interval("10.00", "per_week"),
                        "working_tax_credit":
                        post_money_interval("10.00"),
                        "maintenance":
                        post_money_interval("0"),
                        "pension":
                        post_money_interval("0"),
                        "other_income":
                        post_money_interval("0"),
                    }
                })),
        )

        self.assertEqual(MoneyInterval(5333),
                         mt["you"]["income"]["tax_credits"])
 def assertMeansTestInitialized(self, mt, partner=False):
     self.assertEqual(0, mt["dependants_young"])
     self.assertEqual(0, mt["dependants_old"])
     self.assertEqual(NO, mt["on_passported_benefits"])
     self.assertEqual(NO, mt["on_nass_benefits"])
     self.assertEqual({}, mt["specific_benefits"])
     expected = set(["income", "savings", "deductions"])
     self.assertSetEqual(expected, set(mt["you"].keys()))
     self.assertIncome(mt["you"]["income"], default=MoneyInterval(0))
     self.assertOutgoings(mt["you"]["deductions"], default=MoneyInterval(0))
     self.assertSavings(mt["you"]["savings"], default=0)
     if partner:
         self.assertIncome(mt["partner"]["income"],
                           default=MoneyInterval(0))
         self.assertOutgoings(mt["partner"]["deductions"],
                              default=MoneyInterval(0))
         self.assertSavings(mt["partner"]["savings"], default=0)
Ejemplo n.º 9
0
 def test_add_zero(self):
     mint = MoneyInterval(3)
     total = 0 + mint
     self.assertEqual(3, total.amount)
     self.assertEqual("per_month", total.interval)
     total = mint + 0
     self.assertEqual(3, total.amount)
     self.assertEqual("per_month", total.interval)
    def test_property(self):
        update_session("AboutYouForm", is_employed=YES, have_children=YES)
        session.checker["category"] = "debt"
        mt = MeansTest()
        mt.update_from_form("AboutYouForm", dict(own_property=YES))
        mt.update_from_form("PropertiesForm",
                            properties_post_data(first_property))

        self.assertIncome(
            mt["you"]["income"],
            default=MoneyInterval(0),
            earnings=MoneyInterval(),
            pension=MoneyInterval(),
            maintenance_received=MoneyInterval(),
            self_employed=None,
        )
        self.assertOutgoings(
            mt["you"]["deductions"],
            default=MoneyInterval(),
            criminal_legalaid_contributions=None,
            mortgage=MoneyInterval("800.00", "per_month"),
        )
        self.assertSavings(mt["you"]["savings"], default=0)

        expected = [{
            "value": 1000000,
            "mortgage_left": 900000,
            "share": 100,
            "disputed": NO,
            "rent": MoneyInterval(0),
            "main": YES,
        }]
        self.assertDictEqual(expected[0], mt["property_set"][0])
Ejemplo n.º 11
0
    def __init__(self, form_data={}):
        super(OutgoingsPayload, self).__init__()

        def val(field):
            return form_data.get(field)

        self.update({
            "you": {
                "deductions": {
                    "rent":
                    MoneyInterval(mi("rent", val)),
                    "maintenance":
                    MoneyInterval(mi("maintenance", val)),
                    "criminal_legalaid_contributions":
                    to_amount(val("income_contribution")),
                    "childcare":
                    MoneyInterval(mi("childcare", val)),
                }
            }
        })
        if not session.checker.has_children and not session.checker.has_dependants:
            self["you"]["deductions"]["childcare"] = MoneyInterval(0)
    def test_multiple_rents(self):
        update_session("AboutYouForm", is_employed=YES, have_children=YES)
        session.checker["category"] = "debt"
        mt = MeansTest()
        mt.update_from_form("AboutYouForm", dict(own_property=YES))
        session.checker["AboutYouForm"] = {"own_property": YES}

        prop1 = rented(first_property, post_money_interval("100.00"))
        prop2 = rented(second_property, post_money_interval("50.00"))
        mt.update_from_form("PropertiesForm",
                            properties_post_data(prop1, prop2))
        session.checker["PropertiesForm"] = {"properties": [prop1, prop2]}

        self.assertIncome(
            mt["you"]["income"],
            default=MoneyInterval(0),
            earnings=MoneyInterval(),
            pension=MoneyInterval(),
            maintenance_received=MoneyInterval(),
            other_income=MoneyInterval("150.00"),
            self_employed=None,
        )
Ejemplo n.º 13
0
 def income():
     return {
         "income": {
             "earnings": MoneyInterval(0),
             "tax_credits": MoneyInterval(0),
             "other_income": MoneyInterval(0),
             "self_employment_drawings": MoneyInterval(0),
             "maintenance_received": MoneyInterval(0),
             "pension": MoneyInterval(0),
         },
         "deductions": {
             "income_tax": MoneyInterval(0),
             "national_insurance": MoneyInterval(0)
         },
     }
    def test_benefits_passported(self):
        session.checker["category"] = "debt"
        mt = MeansTest()
        mt.update_from_form("AboutYouForm",
                            about_you_post_data(on_benefits=YES))
        mt.update_from_form("YourBenefitsForm",
                            {"benefits": ["income_support"]})

        self.assertTrue(mt["on_passported_benefits"])
        expected = {
            "income_support": True,
            "job_seekers_allowance": False,
            "pension_credit": False,
            "universal_credit": False,
            "employment_support": False,
        }
        self.assertEqual(expected, mt["specific_benefits"])

        self.assertIncome(mt["you"]["income"], default=MoneyInterval(0))
        self.assertOutgoings(mt["you"]["deductions"], default=MoneyInterval(0))
        self.assertSavings(mt["you"]["savings"], default=0)

        self.assertEqual([], mt["property_set"])
    def test_rent(self):
        session.checker["category"] = "debt"
        mt = MeansTest()

        mt.update_from_form("AboutYouForm", dict(own_property=YES))
        session.checker["AboutYouForm"] = {
            "have_partner": NO,
            "own_property": YES
        }

        prop = rented(first_property, post_money_interval("100.00"))
        mt.update_from_form("PropertiesForm", properties_post_data(prop))
        session.checker["PropertiesForm"] = {"properties": [prop]}

        self.assertIncome(
            mt["you"]["income"],
            default=MoneyInterval(0),
            earnings=MoneyInterval(0),
            pension=MoneyInterval(),
            maintenance_received=MoneyInterval(),
            other_income=MoneyInterval("100.00"),
            self_employed=None,
        )
    def test_child_benefits(self):
        session.checker["category"] = "debt"
        mt = MeansTest()
        mt.update_from_form("AboutYouForm", about_you_post_data())
        post_data = dict(
            flatten({
                "child_benefit": post_money_interval("12", "per_week"),
                "benefits": ["child_benefit"]
            }))
        mt.update_from_form("YourBenefitsForm", post_data)

        self.assertFalse(mt["on_passported_benefits"])
        self.assertEqual(MoneyInterval(1200, "per_week"),
                         mt["you"]["income"]["child_benefits"])
    def test_additional_benefits(self):
        session.checker["category"] = "debt"
        mt = MeansTest()
        mt.update_from_form("AboutYouForm", about_you_post_data())
        post_data = dict(
            flatten({
                "benefits": [],
                "other_benefits": YES,
                "total_other_benefit": post_money_interval("3", "per_week")
            }))
        mt.update_from_form("AdditionalBenefitsForm", post_data)

        self.assertFalse(mt["on_nass_benefits"])
        self.assertEqual(MoneyInterval(300, "per_week"),
                         mt["you"]["income"]["benefits"])
    def test_partner_income(self):
        session.checker["AboutYouForm"] = {
            "have_partner": YES,
            "partner_is_employed": YES
        }

        mt = MeansTest()
        mt.update_from_form(
            "IncomeForm",
            dict(
                flatten({
                    "your_income": {
                        "earnings": post_money_interval("0"),
                        "income_tax": post_money_interval("0"),
                        "national_insurance": post_money_interval("0"),
                        "working_tax_credit": post_money_interval("0"),
                        "maintenance": post_money_interval("0"),
                        "pension": post_money_interval("0"),
                        "other_income": post_money_interval("0"),
                    },
                    "partner_income": {
                        "earnings": post_money_interval("1"),
                        "income_tax": post_money_interval("2"),
                        "national_insurance": post_money_interval("3"),
                        "working_tax_credit": post_money_interval("4"),
                        "maintenance": post_money_interval("5"),
                        "pension": post_money_interval("6"),
                        "other_income": post_money_interval("7"),
                    },
                })),
        )

        self.assertEqual(MoneyInterval(100),
                         mt["partner"]["income"]["earnings"])
        self.assertEqual(MoneyInterval(200),
                         mt["partner"]["deductions"]["income_tax"])
        self.assertEqual(MoneyInterval(300),
                         mt["partner"]["deductions"]["national_insurance"])
        self.assertEqual(MoneyInterval(400),
                         mt["partner"]["income"]["tax_credits"])
        self.assertEqual(MoneyInterval(500),
                         mt["partner"]["income"]["maintenance_received"])
        self.assertEqual(MoneyInterval(600),
                         mt["partner"]["income"]["pension"])
        self.assertEqual(MoneyInterval(700),
                         mt["partner"]["income"]["other_income"])
    def test_income_self_employed(self):
        session.checker["AboutYouForm"] = {
            "is_self_employed": YES,
            "is_employed": NO
        }

        mt = MeansTest()
        mt.update_from_form(
            "AboutYouForm",
            about_you_post_data(is_self_employed=YES, is_employed=NO))
        mt.update_from_form(
            "IncomeForm",
            dict(
                flatten({
                    "your_income": {
                        "earnings": post_money_interval("1"),
                        "income_tax": post_money_interval("2"),
                        "national_insurance": post_money_interval("3"),
                        "working_tax_credit": post_money_interval("4"),
                        "maintenance": post_money_interval("5"),
                        "pension": post_money_interval("6"),
                        "other_income": post_money_interval("7"),
                    }
                })),
        )

        self.assertEqual(MoneyInterval(0), mt["you"]["income"]["earnings"])
        self.assertEqual(MoneyInterval(100),
                         mt["you"]["income"]["self_employment_drawings"])
        self.assertEqual(MoneyInterval(200),
                         mt["you"]["deductions"]["income_tax"])
        self.assertEqual(MoneyInterval(300),
                         mt["you"]["deductions"]["national_insurance"])
        self.assertEqual(MoneyInterval(400),
                         mt["you"]["income"]["tax_credits"])
        self.assertEqual(MoneyInterval(500),
                         mt["you"]["income"]["maintenance_received"])
        self.assertEqual(MoneyInterval(600), mt["you"]["income"]["pension"])
        self.assertEqual(MoneyInterval(700),
                         mt["you"]["income"]["other_income"])
 def assertNullFinances(self,
                        person,
                        income_overrides={},
                        outgoings_overrides={},
                        savings_overrides={}):
     self.assertIncome(person["income"],
                       default=MoneyInterval(0),
                       earnings=MoneyInterval(),
                       pension=MoneyInterval(),
                       maintenance_received=MoneyInterval(),
                       other_income=MoneyInterval(),
                       **income_overrides)
     self.assertOutgoings(person["deductions"],
                          default=MoneyInterval(),
                          mortgage=MoneyInterval(0),
                          criminal_legalaid_contributions=None,
                          **outgoings_overrides)
     self.assertSavings(person["savings"], default=0, **savings_overrides)
    def test_benefits_not_passported(self):
        update_session("AboutYouForm", is_employed=YES, have_children=YES)
        session.checker["category"] = "debt"
        mt = MeansTest()
        mt.update_from_form("AboutYouForm",
                            about_you_post_data(on_benefits=YES))
        mt.update_from_form("YourBenefitsForm", {"benefits": "other-benefit"})

        self.assertFalse(mt["on_passported_benefits"])
        expected = {
            "income_support": False,
            "job_seekers_allowance": False,
            "pension_credit": False,
            "universal_credit": False,
            "employment_support": False,
        }
        self.assertEqual(expected, mt["specific_benefits"])
        self.assertNullFinances(
            mt["you"], income_overrides={"child_benefits": MoneyInterval()})
        self.assertEqual([], mt["property_set"])
Ejemplo n.º 22
0
 def test_add(self):
     mint_a = MoneyInterval(1)
     mint_b = MoneyInterval(2)
     mint_c = mint_a + mint_b
     self.assertEqual(3, mint_c.amount)
     self.assertEqual("per_month", mint_c.interval)
Ejemplo n.º 23
0
        def income(person, prefix_, self_employed=False, employed=False):
            def prefix(field):
                return "{0}-{1}".format(prefix_, field)

            def val(field):
                return form_data.get(prefix(field))

            child_tax_credit = MoneyInterval(
                mi("child_tax_credit",
                   val)) if person == "you" else MoneyInterval(0)
            payload = {
                person: {
                    "income": {
                        "earnings":
                        MoneyInterval(mi("earnings", val)),
                        "self_employment_drawings":
                        MoneyInterval(0),
                        "tax_credits":
                        MoneyInterval(mi("working_tax_credit", val)) +
                        child_tax_credit,
                        "maintenance_received":
                        MoneyInterval(mi("maintenance", val)),
                        "pension":
                        MoneyInterval(mi("pension", val)),
                        "other_income":
                        MoneyInterval(mi("other_income", val)),
                    },
                    "deductions": {
                        "income_tax":
                        MoneyInterval(mi("income_tax", val)),
                        "national_insurance":
                        MoneyInterval(mi("national_insurance", val)),
                    },
                }
            }

            if self_employed:
                payload[person]["income"]["earnings"] = MoneyInterval(0)
                payload[person]["income"][
                    "self_employment_drawings"] = MoneyInterval(
                        mi("earnings", val))

            if not employed:
                payload[person]["income"]["earnings"] = MoneyInterval(0)
                payload[person]["income"][
                    "self_employment_drawings"] = MoneyInterval(0)
                payload[person]["income"]["tax_credits"] = MoneyInterval(0)
                payload[person]["deductions"]["income_tax"] = MoneyInterval(0)
                payload[person]["deductions"][
                    "national_insurance"] = MoneyInterval(0)

            return payload
Ejemplo n.º 24
0
    def __init__(self, form_data={}):
        super(IncomePayload, self).__init__()

        def income(person, prefix_, self_employed=False, employed=False):
            def prefix(field):
                return "{0}-{1}".format(prefix_, field)

            def val(field):
                return form_data.get(prefix(field))

            child_tax_credit = MoneyInterval(
                mi("child_tax_credit",
                   val)) if person == "you" else MoneyInterval(0)
            payload = {
                person: {
                    "income": {
                        "earnings":
                        MoneyInterval(mi("earnings", val)),
                        "self_employment_drawings":
                        MoneyInterval(0),
                        "tax_credits":
                        MoneyInterval(mi("working_tax_credit", val)) +
                        child_tax_credit,
                        "maintenance_received":
                        MoneyInterval(mi("maintenance", val)),
                        "pension":
                        MoneyInterval(mi("pension", val)),
                        "other_income":
                        MoneyInterval(mi("other_income", val)),
                    },
                    "deductions": {
                        "income_tax":
                        MoneyInterval(mi("income_tax", val)),
                        "national_insurance":
                        MoneyInterval(mi("national_insurance", val)),
                    },
                }
            }

            if self_employed:
                payload[person]["income"]["earnings"] = MoneyInterval(0)
                payload[person]["income"][
                    "self_employment_drawings"] = MoneyInterval(
                        mi("earnings", val))

            if not employed:
                payload[person]["income"]["earnings"] = MoneyInterval(0)
                payload[person]["income"][
                    "self_employment_drawings"] = MoneyInterval(0)
                payload[person]["income"]["tax_credits"] = MoneyInterval(0)
                payload[person]["deductions"]["income_tax"] = MoneyInterval(0)
                payload[person]["deductions"][
                    "national_insurance"] = MoneyInterval(0)

            return payload

        payload = income(
            "you",
            "your_income",
            session.checker.is_self_employed
            and not session.checker.is_employed,
            session.checker.is_self_employed or session.checker.is_employed,
        )

        if session.checker.owns_property:
            rents = [
                MoneyInterval(p["rent_amount"]) for p in session.checker.get(
                    "PropertiesForm", {}).get("properties", [])
            ]
            total_rent = sum(rents)
            payload["you"]["income"]["other_income"] += total_rent

        if session.checker.has_partner:
            partner_payload = income(
                "partner",
                "partner_income",
                session.checker.partner_is_self_employed
                and not session.checker.partner_is_employed,
                session.checker.partner_is_self_employed
                or session.checker.partner_is_employed,
            )
            payload = recursive_update(payload, partner_payload)

        self.update(payload)
Ejemplo n.º 25
0
 def zero_finances():
     return {
         "income": {
             "earnings": MoneyInterval(0),
             "benefits": MoneyInterval(0),
             "tax_credits": MoneyInterval(0),
             "child_benefits": MoneyInterval(0),
             "other_income": MoneyInterval(0),
             "self_employment_drawings": MoneyInterval(0),
             "maintenance_received": MoneyInterval(0),
             "pension": MoneyInterval(0),
             "self_employed": NO,
         },
         "savings": {
             "credit_balance": 0,
             "investment_balance": 0,
             "asset_balance": 0,
             "bank_balance": 0
         },
         "deductions": {
             "income_tax": MoneyInterval(0),
             "mortgage": MoneyInterval(0),
             "childcare": MoneyInterval(0),
             "rent": MoneyInterval(0),
             "maintenance": MoneyInterval(0),
             "national_insurance": MoneyInterval(0),
             "criminal_legalaid_contributions": 0,
         },
     }
Ejemplo n.º 26
0
 def test_init_empty(self):
     mint = MoneyInterval()
     self.assertEqual(None, mint.amount)
     self.assertEqual("per_month", mint.interval)
Ejemplo n.º 27
0
 def mortgage(index):
     return MoneyInterval(
         form_data.get("properties-%d-mortgage_payments" % index, 0))
Ejemplo n.º 28
0
 def test_add_different_intervals(self):
     mint_a = MoneyInterval(100, "per_week")
     mint_b = MoneyInterval(100, "per_month")
     mint_c = mint_a + mint_b
     self.assertEqual(533, mint_c.amount)
     self.assertEqual("per_month", mint_c.interval)
Ejemplo n.º 29
0
 def test_add_invalid(self):
     mint = MoneyInterval(100)
     with self.assertRaises(ValueError):
         mint = mint + 1
 def test_normalize_to_per_month(self):
     mint = MoneyInterval(100, "per_week")
     mint = mint.per_month()
     self.assertEqual(433, mint.amount)
     self.assertEqual("per_month", mint.interval)
def money_interval_to_monthly(data):
    return MoneyInterval(data).per_month()
 def test_setters(self):
     mint = MoneyInterval()
     mint.amount = 100
     mint.interval = "per_week"
     self.assertEqual(100, mint.amount)
     self.assertEqual("per_week", mint.interval)