From 2d0512c72b2a8feb6fa10c3cd8b8c53bc74a9ba6 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 28 Apr 2021 09:55:25 +0200 Subject: WIP: preventive forms --- archaeological_files/models.py | 65 ++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 28 deletions(-) (limited to 'archaeological_files/models.py') diff --git a/archaeological_files/models.py b/archaeological_files/models.py index db46c1ca7..fde527ae1 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -521,6 +521,18 @@ class File( ) # <-- research archaeology + # --> preventive detail + study_period = models.CharField(_("Study period"), max_length=200, + default="", blank=True) + start_date = models.DateField(_("Start date"), blank=True, null=True) + end_date = models.DateField(_("End date"), blank=True, null=True) + ground_start_date = models.DateField(_("Ground start date"), blank=True, null=True) + ground_end_date = models.DateField(_("Ground end date"), blank=True, null=True) + execution_report_date = models.DateField(_("Execution report date"), blank=True, + null=True) + linear_meter = models.IntegerField(_("Linear meter"), blank=True, null=True) + # <-- preventive detail + documents = models.ManyToManyField( Document, related_name="files", verbose_name=_("Documents"), blank=True ) @@ -1142,47 +1154,44 @@ class FileDashboard: ) -class PreventiveFile(models.Model): - file = models.ForeignKey(File, verbose_name=_("File")) - study_period = models.CharField(_("Study period"), max_length=200, - default="", blank=True) - start_date = models.DateField(_("Start date"), blank=True, null=True) - end_date = models.DateField(_("End date"), blank=True, null=True) - ground_start_date = models.DateField(_("Ground start date"), blank=True, null=True) - ground_end_date = models.DateField(_("Ground end date"), blank=True, null=True) - execution_report_date = models.DateField(_("Execution report date"), blank=True, - null=True) - linear_meter = models.IntegerField(_("Linear meter"), blank=True, null=True) +class ManDays(models.Model): + man_by_day_planned = models.FloatField( + _("Man by day - planned"), null=True, blank=True) + days_planned = models.FloatField( + _("Days - planned"), null=True, blank=True) + man_by_day_worked = models.FloatField( + _("Man by day - worked"), null=True, blank=True) + days_worked = models.FloatField( + _("Days - worked"), null=True, blank=True) - class Meta: - verbose_name = _("Preventive file") - verbose_name_plural = _("Preventive files") + @property + def man_days_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): + if not self.days_worked or not self.man_by_day_worked: + return 0 + return self.days_worked * self.man_by_day_worked -class ManDays(models.Model): - man_days_planned = models.FloatField( - _("Man-day planned"), null=True, blank=True) - man_days_worked = models.FloatField( - _("Man-day worked"), null=True, blank=True) - class Meta: - abstract = True +class PreventiveFileGroundJob(ManDays): + file = models.ForeignKey(File, related_name="ground_jobs") + job = models.ForeignKey(Job) class PreventiveFileJob(ManDays): - file = models.ForeignKey(PreventiveFile) + file = models.ForeignKey(File, related_name="jobs") job = models.ForeignKey(Job) - ground_man_days_planned = models.FloatField( - _("Ground man-day planned"), null=True, blank=True) - ground_man_days_worked = models.FloatField( - _("Ground man-day worked"), null=True, blank=True) class PreventiveFileEquipmentCost(ManDays): - file = models.ForeignKey(PreventiveFile) + file = models.ForeignKey(File, related_name="equipment_costs") equipment_cost = models.ForeignKey(EquipmentCost) class PreventiveFileTechnicalServiceCost(ManDays): - file = models.ForeignKey(PreventiveFile) + file = models.ForeignKey(File, related_name="technical_service_costs") technical_service_cost = models.ForeignKey(TechnicalServiceCost) -- cgit v1.2.3