Esempio n. 1
0
def objects():

    from lino_welfare.modlib.debts.fixtures.minimal import objects
    yield objects()

    ExcerptType = rt.modules.excerpts.ExcerptType
    kw = dict(
        # template='Default.odt',
        certifying=True)
    kw.update(dd.str2kw('name', _("Financial situation")))
    yield ExcerptType.update_for_model('debts.Budget', **kw)
Esempio n. 2
0
    def test01(self):

        u = users.User(username='******',
                       profile=UserTypes.admin,
                       language="en")
        u.save()
        # be = countries.Country(name="Belgium", isocode="BE")
        # be.save()
        # kw = dict()
        # # kw.update(card_number="123456789")
        # # kw.update(national_id="680601 053-29")
        # kw.update(id=116)
        # kw.update(first_name="Jean")
        # kw.update(middle_name="Jacques")
        # kw.update(last_name="Jeffin")
        # obj = pcsw.Client(**kw)
        # obj.full_clean()
        # obj.save()

        from lino_welfare.modlib.debts.fixtures.minimal import objects
        for o in objects():
            o.save()
        # from lino_xl.lib.households.fixtures.std import objects
        # for o in objects():
        #     o.save()

        # Reproduce ticket #521
        ar = rt.login('root')
        # Member = rt.modules.households.Member
        Household = rt.modules.households.Household
        Person = rt.modules.contacts.Person
        Genders = rt.modules.system.Genders
        Budget = rt.modules.debts.Budget
        
        p1 = Person(first_name="A", last_name="A", gender=Genders.male)
        p1.save()
        p2 = Person(first_name="B", last_name="B", gender=Genders.female)
        p2.save()
        h = Household.create_household(ar, p1, p2, None)

        # The household has for whatever reason an empty member
        # entry. Lino should ignore this entry.
        h.add_member(None)

        b = Budget(partner=h, user=u)
        b.save()
        b.fill_defaults()
        # from django.utils.encoding import force_text
        # s = ' & '.join([force_text(a) for a in b.get_actors()])
        # s = '{0} & {1}'.format(*b.get_actors())
        # self.assertEqual(s, "Mr. & Mrs.")

        ##
        ## Reproduce ticket #159 ('NoneType' object is not iterable
        ## (after duplicating a budget)) and verify ticket #471
        ## (Become the author after duplicating a budget).
        ##
        
        self.assertEqual(b.user.username, 'root')
        self.assertEqual(b.id, 1)

        ou = users.User(username='******',
                        profile=UserTypes.admin,
                        language="en")
        ou.save()
        ar = rt.login('other')
        new = b.duplicate.run_from_code(ar)
        self.assertEqual(new.user.username, 'other')
        self.assertEqual(new.id, 2)
        # new.save()  # must save after on_duplicate
        new = rt.modules.debts.Budget.objects.get(pk=2)
        self.assertEqual(new.user.username, 'other')

        url = "/api/debts/Budgets/1?&an=duplicate&sr=1"
        res = test_client.get(url, REMOTE_USER='******')
        rv = json.loads(res.content)
        self.assertEqual(
            rv['message'],
            u'Duplicated Budget 1 for A-B to Budget 3 for A-B.')
        new = rt.modules.debts.Budget.objects.get(pk=3)

        self.assertEqual(new.user.username, 'other')
Esempio n. 3
0
    def test01(self):
        # print("20180502 test_debts.test01()")

        # Member = rt.models.households.Member
        Household = rt.models.households.Household
        Person = rt.models.contacts.Person
        Genders = rt.models.system.Genders
        Budget = rt.models.debts.Budget
        Actor = rt.models.debts.Actor
        Entry = rt.models.debts.Entry
        
        def check_count(b, a, e):
            self.assertEqual(Budget.objects.count(), b)
            self.assertEqual(Actor.objects.count(), a)
            self.assertEqual(Entry.objects.count(), e)
        
        

        u = users.User(username='******',
                       user_type=UserTypes.admin,
                       language="en")
        u.save()
        # be = countries.Country(name="Belgium", isocode="BE")
        # be.save()
        # kw = dict()
        # # kw.update(card_number="123456789")
        # # kw.update(national_id="680601 053-29")
        # kw.update(id=116)
        # kw.update(first_name="Jean")
        # kw.update(middle_name="Jacques")
        # kw.update(last_name="Jeffin")
        # obj = pcsw.Client(**kw)
        # obj.full_clean()
        # obj.save()

        from lino_welfare.modlib.debts.fixtures.minimal import objects
        for o in objects():
            o.save()
        # from lino_xl.lib.households.fixtures.std import objects
        # for o in objects():
        #     o.save()

        # Reproduce ticket #521
        ar = rt.login('root')
        
        p1 = Person(first_name="A", last_name="A", gender=Genders.male)
        p1.save()
        p2 = Person(first_name="B", last_name="B", gender=Genders.female)
        p2.save()
        h = Household.create_household(ar, p1, p2, None)

        # The household has for whatever reason an empty member
        # entry. Lino should ignore this entry.
        h.add_member(None)

        check_count(0, 0, 0)
        
        b = Budget(partner=h, user=u)
        b.save()
        b.fill_defaults()
        # from django.utils.encoding import force_text
        # s = ' & '.join([force_text(a) for a in b.get_actors()])
        # s = '{0} & {1}'.format(*b.get_actors())
        # self.assertEqual(s, "Mr. & Mrs.")

        ##
        ## Reproduce ticket #159 ('NoneType' object is not iterable
        ## (after duplicating a budget)) and verify ticket #471
        ## (Become the author after duplicating a budget).
        ##
        
        self.assertEqual(b.user.username, 'root')
        self.assertEqual(b.id, 1)

        ou = users.User(username='******',
                        user_type=UserTypes.admin,
                        language="en")
        ou.save()
        ar = rt.login('other')

        check_count(1, 2, 44)
        
        new = b.duplicate.run_from_code(ar)
        self.assertEqual(new.user.username, 'other')
        self.assertEqual(new.id, 2)
        
        check_count(2, 4, 88)
        new = Budget.objects.get(pk=2)
        self.assertEqual(new.user.username, 'other')
       
        url = "/api/debts/Budgets/1?&an=duplicate&sr=1"
        dlg = []
        dlg.append((
            "This will create a copy of Budget 1 for A & B A-B Are you sure?",
            'yes'))
        dlg.append((
            'Duplicated Budget 1 for A & B A-B to Budget 3 for A & B A-B.',
            None))
        self.check_callback_dialog(self.client.get, 'other', url, dlg)

        check_count(3, 6, 132)

        new = Budget.objects.get(pk=3)
        self.assertEqual(new.user.username, 'other')