From 2836cae57302f572bf3993a53fc61d4ffe56f16e Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 8 Jul 2021 11:43:33 +0200 Subject: Files preventive - update model --- archaeological_files/models.py | 62 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 6 deletions(-) (limited to 'archaeological_files/models.py') diff --git a/archaeological_files/models.py b/archaeological_files/models.py index fde527ae1..87abd4083 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -77,6 +77,13 @@ class Job(GeneralType): _("Default daily number needed on the ground"), default=0) default_daily_need = models.FloatField( _("Default daily number needed"), default=0) + order = models.IntegerField(_("Order"), default=10) + parents = models.ManyToManyField( + "self", + blank=True, + verbose_name=_("Parents"), + help_text=_("Auto-add this job when a parent is added") + ) class Meta: verbose_name = _("Job") @@ -113,6 +120,13 @@ class EquipmentCost(models.Model): wednesday = models.BooleanField(_("Wednesday"), default=True) thursday = models.BooleanField(_("Thursday"), default=True) friday = models.BooleanField(_("Friday"), default=True) + order = models.IntegerField(_("Order"), default=10) + parents = models.ManyToManyField( + "self", + blank=True, + verbose_name=_("Parents"), + help_text=_("Auto-add this cost when a parent is added") + ) class Meta: verbose_name = _("Equipment cost") @@ -141,10 +155,17 @@ class TechnicalServiceCost(models.Model): unitary_cost = models.FloatField(_("Unitary cost"), blank=True, null=True) unit = models.CharField(_("Unit"), max_length=1, choices=TECH_UNITS, blank=True, null=True) + order = models.IntegerField(_("Order"), default=10) + parents = models.ManyToManyField( + "self", + blank=True, + verbose_name=_("Parents"), + help_text=_("Auto-add this cost when a parent is added") + ) class Meta: - verbose_name = _("Equipment cost") - verbose_name_plural = _("Equipment costs") + verbose_name = _("Technical service cost") + verbose_name_plural = _("Technical service costs") class FileType(GeneralType): @@ -1164,14 +1185,17 @@ class ManDays(models.Model): days_worked = models.FloatField( _("Days - worked"), null=True, blank=True) + class Meta: + abstract = True + @property - def man_days_planned(self): + def quantity_planned(self): if not self.days_planned or not self.man_by_day_planned: return 0 return self.days_planned * self.man_by_day_planned @property - def man_days_worked(self): + def quantity_worked(self): if not self.days_worked or not self.man_by_day_worked: return 0 return self.days_worked * self.man_by_day_worked @@ -1187,11 +1211,37 @@ class PreventiveFileJob(ManDays): job = models.ForeignKey(Job) -class PreventiveFileEquipmentCost(ManDays): +class TechDays(models.Model): + quantity_by_day_planned = models.FloatField( + _("Quantity by day - planned"), null=True, blank=True) + days_planned = models.FloatField( + _("Days - planned"), null=True, blank=True) + quantity_by_day_worked = models.FloatField( + _("Quantity by day - worked"), null=True, blank=True) + days_worked = models.FloatField( + _("Days - worked"), null=True, blank=True) + + class Meta: + abstract = True + + @property + def quantity_planned(self): + if not self.days_planned or not self.quantity_by_day_planned: + return 0 + return self.days_planned * self.quantity_by_day_planned + + @property + def quantity_worked(self): + if not self.days_worked or not self.quantity_by_day_worked: + return 0 + return self.days_worked * self.quantity_by_day_worked + + +class PreventiveFileEquipmentCost(TechDays): file = models.ForeignKey(File, related_name="equipment_costs") equipment_cost = models.ForeignKey(EquipmentCost) -class PreventiveFileTechnicalServiceCost(ManDays): +class PreventiveFileTechnicalServiceCost(TechDays): file = models.ForeignKey(File, related_name="technical_service_costs") technical_service_cost = models.ForeignKey(TechnicalServiceCost) -- cgit v1.2.3