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 _
|
2018-08-07 20:29:37 +02:00
|
|
|
from django.contrib.auth.models import Group
|
2017-07-21 16:18:19 +02:00
|
|
|
from event.models import Activity, EventSpecificMixin
|
2016-10-14 13:02:25 +02:00
|
|
|
|
2018-08-02 17:55:27 +02:00
|
|
|
from .fields import IdField
|
|
|
|
|
2018-07-26 15:53:42 +02:00
|
|
|
from taggit.managers import TaggableManager
|
2018-08-04 05:38:03 +02:00
|
|
|
from datetime import date
|
2018-07-26 15:53:42 +02:00
|
|
|
|
2016-10-14 13:02:25 +02:00
|
|
|
|
2018-08-06 17:06:38 +02:00
|
|
|
class EquipmentPole(models.Model):
|
|
|
|
name = models.CharField(
|
|
|
|
_("nom"),
|
|
|
|
max_length=200,
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2018-08-06 19:31:34 +02:00
|
|
|
verbose_name = _("pôle")
|
|
|
|
verbose_name_plural = _("pôle")
|
2018-08-06 17:06:38 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class EquipmentCategory(models.Model):
|
|
|
|
name = models.CharField(
|
|
|
|
_("nom"),
|
|
|
|
max_length=200,
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
2018-08-06 19:31:34 +02:00
|
|
|
verbose_name = _("catégories")
|
|
|
|
verbose_name_plural = _("catégories")
|
2018-08-06 17:06:38 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
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",
|
|
|
|
)
|
2018-08-07 20:44:57 +02:00
|
|
|
owner = models.ForeignKey(
|
|
|
|
Group,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
2018-08-06 17:06:38 +02:00
|
|
|
pole = models.ForeignKey(
|
|
|
|
EquipmentPole,
|
|
|
|
)
|
|
|
|
category = models.ForeignKey(
|
|
|
|
EquipmentCategory,
|
|
|
|
)
|
2018-07-26 15:53:42 +02:00
|
|
|
|
2016-10-14 13:02:25 +02:00
|
|
|
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)
|
2018-08-02 17:55:27 +02:00
|
|
|
amount = models.BigIntegerField(_("quantité attribuée"))
|
2017-07-15 17:44:15 +02:00
|
|
|
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
|
|
|
|
2018-08-07 19:08:20 +02:00
|
|
|
class EquipmentDefault(models.Model):
|
|
|
|
remark = models.TextField(_("remarque sur le défaut"))
|
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",
|
2018-08-07 19:08:20 +02:00
|
|
|
help_text=_("Matériel concerné par le defaut"),
|
2016-10-14 13:02:25 +02:00
|
|
|
)
|
2018-08-06 18:34:07 +02:00
|
|
|
ids = IdField()
|
2018-08-07 19:08:20 +02:00
|
|
|
is_unusable = models.BooleanField(_("inutilisable"))
|
|
|
|
send_repare = models.BooleanField(_("à envoyer réparareur"))
|
2016-10-14 13:02:25 +02:00
|
|
|
|
|
|
|
class Meta:
|
2018-08-07 19:08:20 +02:00
|
|
|
verbose_name = _("defaut matériel")
|
|
|
|
verbose_name_plural = _("défauts sur le matériel")
|
2016-10-14 13:02:25 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
2016-10-21 18:49:46 +02:00
|
|
|
return "%s : %s" % (self.equipment.name,
|
|
|
|
self.remark)
|
2018-08-04 05:38:03 +02:00
|
|
|
|
|
|
|
|
2018-08-07 19:08:20 +02:00
|
|
|
class EquipmentLost(models.Model):
|
|
|
|
lost_at = models.DateField(
|
|
|
|
_("perdu le"),
|
|
|
|
default=date.today,
|
|
|
|
)
|
|
|
|
equipment = models.ForeignKey(
|
|
|
|
Equipment,
|
|
|
|
related_name="losts",
|
|
|
|
help_text=_("Matériel concerné par la perte"),
|
|
|
|
)
|
|
|
|
ids = IdField()
|
|
|
|
|
|
|
|
|
2018-08-04 05:38:03 +02:00
|
|
|
class EquipmentRevision(models.Model):
|
|
|
|
date = models.DateField(
|
|
|
|
_("date"),
|
|
|
|
default=date.today,
|
|
|
|
)
|
|
|
|
equipment = models.ForeignKey(
|
|
|
|
Equipment,
|
|
|
|
related_name="revisions",
|
|
|
|
help_text=_("Matériel concerné par les révisions"),
|
|
|
|
)
|
|
|
|
remark = models.TextField(_("remarque sur la révision"))
|
2018-08-06 18:34:07 +02:00
|
|
|
ids = IdField()
|
2018-08-04 05:38:03 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("révision de matériel")
|
|
|
|
verbose_name_plural = _("révisions de matériel")
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "%s : %s" % (self.equipment.name,
|
|
|
|
self.remark)
|