2016-10-14 13:02:25 +02:00
|
|
|
from django.db import models
|
2017-07-21 16:18:19 +02:00
|
|
|
from django.core.exceptions import ValidationError
|
2016-10-14 13:02:25 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2017-07-21 16:18:19 +02:00
|
|
|
from event.models import Activity, EventSpecificMixin
|
2016-10-14 13:02:25 +02:00
|
|
|
|
|
|
|
|
2017-07-18 19:08:09 +02:00
|
|
|
class Equipment(EventSpecificMixin, models.Model):
|
2016-10-14 13:02:25 +02:00
|
|
|
name = models.CharField(
|
2017-07-15 17:44:15 +02:00
|
|
|
_("nom du matériel"),
|
2016-10-14 13:02:25 +02:00
|
|
|
max_length=200,
|
|
|
|
)
|
2017-07-15 17:44:15 +02:00
|
|
|
stock = models.PositiveSmallIntegerField(_("quantité disponible"))
|
|
|
|
description = models.TextField(_("description"))
|
2016-10-14 13:02:25 +02:00
|
|
|
activities = models.ManyToManyField(
|
|
|
|
Activity,
|
|
|
|
related_name="equipment",
|
|
|
|
through="EquipmentAttribution",
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2017-07-21 16:18:19 +02:00
|
|
|
verbose_name = _("matériel")
|
|
|
|
verbose_name_plural = _("matériels")
|
2016-10-14 13:02:25 +02:00
|
|
|
|
2017-07-18 19:08:09 +02:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2016-10-14 13:02:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
class EquipmentAttribution(models.Model):
|
2017-07-18 19:08:09 +02:00
|
|
|
equipment = models.ForeignKey(Equipment)
|
2016-10-14 13:02:25 +02:00
|
|
|
activity = models.ForeignKey(Activity)
|
2017-07-15 17:44:15 +02:00
|
|
|
amount = models.PositiveSmallIntegerField(_("quantité attribuée"))
|
|
|
|
remarks = models.TextField(_("remarques concernant l'attribution"))
|
2016-10-14 13:02:25 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("attribution de matériel")
|
|
|
|
verbose_name_plural = _("attributions de matériel")
|
|
|
|
|
|
|
|
def __str__(self):
|
2016-10-21 18:49:46 +02:00
|
|
|
return "%s (%d) -> %s" % (self.equipment.name,
|
|
|
|
self.amout,
|
|
|
|
self.activity.get_herited('title'))
|
2016-10-14 13:02:25 +02:00
|
|
|
|
2017-07-21 16:18:19 +02:00
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
if self.equipment.event and self.equipment.event != self.activity.event:
|
|
|
|
raise ValidationError
|
|
|
|
|
|
|
|
super(EquipmentAttribution, self).save(*args, **kwargs)
|
|
|
|
|
2016-10-14 13:02:25 +02:00
|
|
|
|
|
|
|
class EquipmentRemark(models.Model):
|
2017-07-15 17:44:15 +02:00
|
|
|
remark = models.TextField(_("remarque sur le matériel"))
|
2016-10-14 13:02:25 +02:00
|
|
|
equipment = models.ForeignKey(
|
2017-07-18 19:08:09 +02:00
|
|
|
Equipment,
|
2016-10-14 13:02:25 +02:00
|
|
|
related_name="remarks",
|
|
|
|
help_text=_("Matériel concerné par la remarque"),
|
|
|
|
)
|
2017-07-15 17:50:15 +02:00
|
|
|
amount = models.PositiveSmallIntegerField(_("quantité concernée"))
|
2016-10-14 13:02:25 +02:00
|
|
|
is_broken = models.BooleanField()
|
|
|
|
is_lost = models.BooleanField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("remarque sur matériel")
|
|
|
|
verbose_name_plural = _("remarques sur le matériel")
|
|
|
|
|
|
|
|
def __str__(self):
|
2016-10-21 18:49:46 +02:00
|
|
|
return "%s : %s" % (self.equipment.name,
|
|
|
|
self.remark)
|