Commit ee8eb45e authored by jocelyn's avatar jocelyn

Forbid adding a loan when there is already one running

parent 5323c072
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Q
from django.conf import settings
......@@ -172,6 +173,18 @@ class Loan(models.Model):
is_running.boolean = True
is_running.short_description = 'En cours ?'
def clean(self):
current_loan = self.item.get_current_loan()
if (
self.is_running()
and
current_loan
and
self.item.get_current_loan() != self
):
raise ValidationError(
"Il y a déjà un emprunt en cours sur cet objet")
class Meta:
verbose_name = 'prêt d’objet'
verbose_name_plural = 'prêts d’objets'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment