diff --git a/cotisations/models.py b/cotisations/models.py index 66a89abb..be25ea68 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -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): """ diff --git a/cotisations/validators.py b/cotisations/validators.py new file mode 100644 index 00000000..fa8ea2cf --- /dev/null +++ b/cotisations/validators.py @@ -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") + )