poulpe/equipment/models.py
2017-07-15 17:50:15 +02:00

79 lines
2.6 KiB
Python

from django.db import models
from django.utils.translation import ugettext_lazy as _
from event.models import Event, Activity
class AbstractEquipment(models.Model):
name = models.CharField(
_("nom du matériel"),
max_length=200,
)
stock = models.PositiveSmallIntegerField(_("quantité disponible"))
description = models.TextField(_("description"))
activities = models.ManyToManyField(
Activity,
related_name="equipment",
through="EquipmentAttribution",
)
class Meta:
verbose_name = _("matériel abstrait")
verbose_name_plural = _("matériels abstraits")
def __str__(self):
return self.name
class Equipment(AbstractEquipment):
class Meta:
verbose_name = _("matériel permanent")
verbose_name_plural = _("matériels permanents")
class TemporaryEquipment(AbstractEquipment):
event = models.ForeignKey(
Event,
related_name="specific_equipment",
help_text=_("Évènement pour lequel le matériel "
"a été loué ou emprunté ou apporté"),
)
class Meta:
verbose_name = _("matériel temporaire")
verbose_name_plural = _("matériels temporaires")
class EquipmentAttribution(models.Model):
equipment = models.ForeignKey(AbstractEquipment)
activity = models.ForeignKey(Activity)
amount = models.PositiveSmallIntegerField(_("quantité attribuée"))
remarks = models.TextField(_("remarques concernant l'attribution"))
class Meta:
verbose_name = _("attribution de matériel")
verbose_name_plural = _("attributions de matériel")
def __str__(self):
return "%s (%d) -> %s" % (self.equipment.name,
self.amout,
self.activity.get_herited('title'))
class EquipmentRemark(models.Model):
remark = models.TextField(_("remarque sur le matériel"))
equipment = models.ForeignKey(
AbstractEquipment,
related_name="remarks",
help_text=_("Matériel concerné par la remarque"),
)
amount = models.PositiveSmallIntegerField(_("quantité concernée"))
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):
return "%s : %s" % (self.equipment.name,
self.remark)