示例#1
0
    def test_depense_without_naturecomptable_with_enveloppe(self):
        post_data = {
            'annee': self.periode.annee,
            'pfi': self.pfi.pk,
            'naturecomptabledepense': self.natures,
            'enveloppe': 'Fonctionnement',
            'structure': self.pfi.structure.pk,
            'domainefonctionnel': self.domaine.pk,
            'periodebudget': self.periode.pk,
            'montant_ae': Decimal(0),
            'montant_cp': Decimal(0),
            'montant_dc': Decimal(0),
        }

        form_kwargs = {
            'annee': self.periode.annee,
            'periodebudget': self.periode,
            'pfi': self.pfi,
            'is_dfi_member_or_admin': True,
            'natures': self.natures,
            'domaines': self.domaines,
            'user': self.user1
        }

        form = DepenseForm(data=post_data, **form_kwargs)
        self.assertTrue(form.is_bound)
        self.assertFalse(form.is_valid())
        form.clean()
示例#2
0
    def test_edit_depense_not_decalage_treso(self):
        naturecomptabledepense = NatureComptableDepense.objects.get(
            code_nature_comptable='9DCFG', is_fleche=self.pfi.is_fleche)
        depense = Depense.objects.create(
            naturecomptabledepense=naturecomptabledepense,
            pfi=self.pfi,
            structure=self.pfi.structure,
            domainefonctionnel=self.domaine,
            annee=self.periode.annee,
            periodebudget=self.periode,
            montant_ae=Decimal(20),
            montant_cp=Decimal(20),
            montant_dc=Decimal(0),
            creepar='user2')
        form_kwargs = {
            'annee': self.periode.annee,
            'periodebudget': self.periode,
            'pfi': self.pfi,
            'is_dfi_member_or_admin': False,
            'natures': self.natures,
            'domaines': self.domaines,
            'user': self.user1
        }

        form = DepenseForm(instance=depense, **form_kwargs)
        self.assertEqual(form.fields['naturecomptabledepense'].initial.pk,
                         naturecomptabledepense.pk)

        depense = form.save()
        self.assertIsNotNone(depense)
        self.assertEqual(depense.creepar, 'user2')
        self.assertEqual(depense.modifiepar, 'user1')
示例#3
0
    def edit_depense(self, naturecomptabledepense):
        depense = Depense.objects.create(
            naturecomptabledepense=naturecomptabledepense,
            pfi=self.pfi,
            structure=self.pfi.structure,
            domainefonctionnel=self.domaine,
            annee=self.periode.annee,
            periodebudget=self.periode,
            montant_ae=Decimal(1),
            montant_cp=Decimal(2),
            montant_dc=Decimal(3),
            creepar='user2')
        form_kwargs = {
            'annee': self.periode.annee,
            'periodebudget': self.periode,
            'pfi': self.pfi,
            'is_dfi_member_or_admin': True,
            'natures': self.natures,
            'domaines': self.domaines,
            'user': self.user1
        }

        form = DepenseForm(instance=depense, **form_kwargs)
        self.assertEqual(form.fields['naturecomptabledepense'].initial.pk,
                         naturecomptabledepense.pk)

        depense = form.save()
        self.assertIsNotNone(depense)
        self.assertEqual(depense.creepar, 'user2')
        self.assertEqual(depense.modifiepar, 'user1')
示例#4
0
    def test_add_depense_all_without_error_ae_cp_dc(self):
        naturecomptabledepense = NatureComptableDepense.objects.get(
            code_nature_comptable='9DTAX', is_fleche=self.pfi.is_fleche)
        post_data = {
            'annee': self.periode.annee,
            'naturecomptabledepense': naturecomptabledepense.pk,
            'pfi': self.pfi.pk,
            'structure': self.pfi.structure.pk,
            'domainefonctionnel': self.domaine.pk,
            'periodebudget': self.periode.pk,
            'montant_ae': Decimal(20),
            'montant_cp': Decimal(20),
            'montant_dc': Decimal(20),
        }

        form_kwargs = {
            'annee': self.periode.annee,
            'periodebudget': self.periode,
            'pfi': self.pfi,
            'is_dfi_member_or_admin': False,
            'natures': self.natures,
            'domaines': self.domaines,
            'user': self.user1
        }

        form = DepenseForm(data=post_data, **form_kwargs)
        self.assertTrue(form.is_bound)
        self.assertTrue(form.is_valid())
        depense = form.save()
        self.assertIsNotNone(depense)
        self.assertEqual(depense.creepar, 'user1')
        self.assertEqual(depense.modifiepar, 'user1')
示例#5
0
    def add_depense(self, naturecomptabledepense, is_admin_or_not):
        post_data = {
            'annee': self.periode.annee,
            'naturecomptabledepense': naturecomptabledepense.pk,
            'pfi': self.pfi.pk,
            'structure': self.pfi.structure.pk,
            'domainefonctionnel': self.domaine.pk,
            'periodebudget': self.periode.pk,
            'montant_ae': Decimal(1),
            'montant_cp': Decimal(2),
            'montant_dc': Decimal(3),
        }

        form_kwargs = {
            'annee': self.periode.annee,
            'periodebudget': self.periode,
            'pfi': self.pfi,
            'is_dfi_member_or_admin': is_admin_or_not,
            'natures': self.natures,
            'domaines': self.domaines,
            'user': self.user1
        }

        form = DepenseForm(data=post_data, **form_kwargs)
        return form
示例#6
0
    def test_add_depense_non_budgetaire_cp_not_null(self):
        naturecomptabledepense = NatureComptableDepense.objects.get(
            code_nature_comptable='9DAMO', is_fleche=self.pfi.is_fleche)
        post_data = {
            'annee': self.periode.annee,
            'naturecomptabledepense': naturecomptabledepense.pk,
            'pfi': self.pfi.pk,
            'structure': self.pfi.structure.pk,
            'domainefonctionnel': self.domaine.pk,
            'periodebudget': self.periode.pk,
            'montant_ae': Decimal(0),
            'montant_cp': Decimal(10),
            'montant_dc': Decimal(20),
        }

        form_kwargs = {
            'annee': self.periode.annee,
            'periodebudget': self.periode,
            'pfi': self.pfi,
            'is_dfi_member_or_admin': False,
            'natures': self.natures,
            'domaines': self.domaines,
            'user': self.user1
        }

        form = DepenseForm(data=post_data, **form_kwargs)
        self.assertTrue(form.is_bound)
        with self.assertRaises(forms.ValidationError) as e:
            form.is_valid()
            form.clean()
        self.assertRegexpMatches(e.exception.message,
                                 'Le montant CP ne peut être différent de 0')