2018-07-13 15:33:08 +00:00
|
|
|
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
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-07-13 15:33:08 +00:00
|
|
|
if not is_balance:
|
|
|
|
return
|
|
|
|
p = Paiement.objects.filter(is_balance=True)
|
|
|
|
if len(p) > 0:
|
2019-11-04 16:55:03 +00:00
|
|
|
raise ValidationError(_("There is already a payment method for user balance."))
|