Beispiel #1
0
 def save_model(self, request, obj, form, change):
     """
     Given a model instance save it to the database.
     """
     if not change:
         obj.etat = etat_initial(obj, request.user)
     super().save_model(request, obj, form, change)
    def test_creation_dans_etat_attente_engagement(self):
        d = Depense(
            titre="Ma dépense",
            compte=self.compte,
            type=TypeDepense.FRAIS_RECEPTION_HEBERGEMENT,
            montant=45.20,
        )

        self.assertEqual(etat_initial(d, self.person.role),
                         Depense.Etat.ATTENTE_ENGAGEMENT)
    def test_creation_dans_etat_attente_engagement_avec_permission(self):
        Autorisation.objects.create(compte=self.compte,
                                    group=self.group,
                                    autorisations=["engager_depense"])
        d = Depense(
            titre="Ma dépense",
            compte=self.compte,
            type=TypeDepense.FRAIS_RECEPTION_HEBERGEMENT,
            montant=45.20,
        )

        self.assertEqual(etat_initial(d, self.person.role),
                         Depense.Etat.CONSTITUTION)
    def test_creation_au_dessus_plafond_sans_engagement(
            self, types_depense, montants):
        type_parent, type_enfant = types_depense
        plafond, montant_depense = montants

        self.compte.engagement_automatique[type_parent] = plafond
        self.compte.save()

        d = Depense(
            titre="Ma dépense !",
            compte=self.compte,
            type=type_enfant,
            montant=montant_depense,
        )

        self.assertEqual(etat_initial(d, self.person.role),
                         Depense.Etat.ATTENTE_ENGAGEMENT)
    def test_creation_sous_plafond_engagement(self, types_depense, montants):
        type_parent, type_enfant = types_depense
        montant_depense, plafond = montants

        self.compte.engagement_automatique[type_parent] = plafond
        self.compte.save()

        self.assertTrue(self.person.has_perm("gestion.gerer_depense"))

        d = Depense(
            titre="Ma dépense !",
            compte=self.compte,
            type=type_enfant,
            montant=montant_depense,
        )

        self.assertEqual(etat_initial(d, self.person.role),
                         Depense.Etat.CONSTITUTION)