8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 07:02:26 +00:00

Un fichier validators pour les validator.

This commit is contained in:
Hugo LEVY-FALK 2018-07-13 17:33:08 +02:00
parent c819cc891d
commit 8061c3283c
2 changed files with 22 additions and 12 deletions

View file

@ -52,6 +52,7 @@ from re2o.field_permissions import FieldPermissionModelMixin
from re2o.mixins import AclMixin, RevMixin
from cotisations.utils import find_payment_method
from cotisations.validators import check_no_balance
# TODO : change facture to invoice
@ -605,18 +606,6 @@ class Banque(RevMixin, AclMixin, models.Model):
return self.name
def check_no_balance():
"""This functions checks that no Paiement with is_balance=True exists
Raises:
ValidationError: if such a Paiement exists.
"""
p = Paiement.objects.filter(is_balance=True)
if len(p)>0:
raise ValidationError(
_("There are already payment method(s) for user balance")
)
# TODO : change Paiement to Payment
class Paiement(RevMixin, AclMixin, models.Model):
"""

21
cotisations/validators.py Normal file
View file

@ -0,0 +1,21 @@
from django.forms import ValidationError
from django.utils.translation import ugettext as _
def check_no_balance(is_balance):
"""This functions checks that no Paiement with is_balance=True exists
Args:
is_balance: True if the model is balance.
Raises:
ValidationError: if such a Paiement exists.
"""
from .models import Paiement
if not is_balance:
return
p = Paiement.objects.filter(is_balance=True)
if len(p) > 0:
raise ValidationError(
_("There are already payment method(s) for user balance")
)