From e2d25ef68858b42dee3f0c7b1582004ef0a013bb Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 6 Sep 2024 12:51:31 +0100 Subject: Tidying up effort interface --- engagements/models.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'engagements/models.py') diff --git a/engagements/models.py b/engagements/models.py index 20bed8d..b0dfe2b 100644 --- a/engagements/models.py +++ b/engagements/models.py @@ -154,6 +154,9 @@ class Engagement(Common): "L4RIF": "L4 RIF", } + def get_officers(self): + return [" ".join([x.first_name, x.last_name]) for x in self.officers.all()] + def total_planning_effort(self): p_effort = self.engagementeffort_set.all().filter(is_planned=True) return sum([x.effort_total_hours() for x in p_effort]) @@ -173,7 +176,7 @@ class Engagement(Common): def dscs(self): "Return all declared DSCs as part of REGULATION effort" dscs = set() - for ee in EngagementEffort.objects.filter(engagement=self, effort_type="REGULATION"): + for ee in EngagementEffort.objects.filter(engagement=self): for si in ee.sub_instruments.all(): dscs.add(si) return dscs @@ -191,7 +194,7 @@ class EngagementEffort(Common): ("PLANNING", "Planning"), ("REGULATION", "Regulation (On-site or Remote)"), ("DISCUSSION", "Discussion"), - ("REPORT", "Reporting"), + ("REPORTING", "Reporting"), ) is_planned = models.BooleanField(null=True, blank=True, verbose_name="Planned", default=True) effort_type = models.CharField(max_length=32, choices=choices, verbose_name="Effort Type") @@ -206,6 +209,9 @@ class EngagementEffort(Common): verbose_name_plural = "Engagement Effort" ordering = ("proposed_start_date",) + def get_officers(self): + return [" ".join([x.first_name, x.last_name]) for x in self.officers.all()] + def effort_total_hours(self): "Returns total effort for this engagement." delta = self.proposed_end_date - self.proposed_start_date -- cgit v1.2.3 From 5fb0621c53967bf24f4411f579712223e96b296a Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Tue, 10 Sep 2024 12:11:12 +0100 Subject: Adds RegulatoryCycle model --- engagements/models.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'engagements/models.py') diff --git a/engagements/models.py b/engagements/models.py index b0dfe2b..ef0aee3 100644 --- a/engagements/models.py +++ b/engagements/models.py @@ -27,6 +27,7 @@ class RegulatoryRole(Common): class Person(Common): "External person, rather than MOD at this point." + first_name = models.CharField(max_length=64, null=False, blank=False) last_name = models.CharField(max_length=64, null=False, blank=False) organisation = models.ForeignKey("Organisation", null=False, blank=False, on_delete=models.CASCADE) @@ -240,3 +241,23 @@ class EngagementEffort(Common): def __str__(self): return f"{self.effort_type} effort for {self.engagement}: {self.proposed_end_date - self.proposed_start_date}" + + +class RegulatoryCycle(Common): + start_date = models.DateField(null=False, blank=False) + end_date = models.DateField(null=False, blank=False) + description = models.TextField(max_length=1024, null=True, blank=True) + + def get_year(self): + return str(self.start_date.year) + + def __str__(self): + return f"Regulatory Cycle: {self.get_year()}" + + +# class EngagementStrategy(Common): +# name = models.CharField(max_length=128, null=False, blank=False) +# start_date = models.DateField(null=False, blank=False) +# end_date +# description = models.TextField(max_length=1024) +# engagement = models.ForeignKey(Engagement, on_delete=models.CASCADE) -- cgit v1.2.3 From c4fd33fce3dbef280657c150a7658462c80da877 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Tue, 10 Sep 2024 12:34:49 +0100 Subject: wip: implementing EngagementStrategy --- engagements/models.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'engagements/models.py') diff --git a/engagements/models.py b/engagements/models.py index ef0aee3..8876d91 100644 --- a/engagements/models.py +++ b/engagements/models.py @@ -255,9 +255,19 @@ class RegulatoryCycle(Common): return f"Regulatory Cycle: {self.get_year()}" -# class EngagementStrategy(Common): -# name = models.CharField(max_length=128, null=False, blank=False) -# start_date = models.DateField(null=False, blank=False) -# end_date -# description = models.TextField(max_length=1024) -# engagement = models.ForeignKey(Engagement, on_delete=models.CASCADE) +class EngagementStrategy(Common): + STATUS = ( + ("DRAFT", "Draft"), + ("SUBMITTED", "Submitted"), + ("APPROVED", "Approved"), + ("REJECTED", "Rejected"), + ) + + name = models.CharField(max_length=128, null=False, blank=False) + organisation = models.ForeignKey(Organisation, on_delete=models.CASCADE) + start_year = models.ForeignKey(RegulatoryCycle, on_delete=models.CASCADE, related_name="start_year") + end_year = models.ForeignKey(RegulatoryCycle, on_delete=models.CASCADE, related_name="end_year") + description = models.TextField(max_length=1024) + inspector_sign_off = models.DateField(null=True, blank=True) + management_sign_off = models.DateField(null=True, blank=True) + status = models.CharField(max_length=32, choices=STATUS, default=STATUS[0][0]) -- cgit v1.2.3 From 15eceda8c762c3e3890f2c160d1c89c36a7b398b Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Tue, 10 Sep 2024 14:08:35 +0100 Subject: ES basically done --- engagements/models.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'engagements/models.py') diff --git a/engagements/models.py b/engagements/models.py index 8876d91..45d8e69 100644 --- a/engagements/models.py +++ b/engagements/models.py @@ -5,6 +5,8 @@ from django.utils.text import slugify from myuser.models import TeamUser +ES_YEAR_LENGTH = 3 + class Common(models.Model): date_created = models.DateTimeField(auto_now_add=True) @@ -263,11 +265,33 @@ class EngagementStrategy(Common): ("REJECTED", "Rejected"), ) - name = models.CharField(max_length=128, null=False, blank=False) organisation = models.ForeignKey(Organisation, on_delete=models.CASCADE) start_year = models.ForeignKey(RegulatoryCycle, on_delete=models.CASCADE, related_name="start_year") end_year = models.ForeignKey(RegulatoryCycle, on_delete=models.CASCADE, related_name="end_year") - description = models.TextField(max_length=1024) + description = models.TextField(max_length=1024, null=True, blank=True) inspector_sign_off = models.DateField(null=True, blank=True) + owned_by = models.ForeignKey( + settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="owned_engagement_strategies" + ) + reviewed_by = models.ForeignKey( + settings.AUTH_USER_MODEL, + null=True, + blank=True, + on_delete=models.CASCADE, + related_name="reviewed_engagement_strategies", + ) management_sign_off = models.DateField(null=True, blank=True) status = models.CharField(max_length=32, choices=STATUS, default=STATUS[0][0]) + + def get_end_year(self) -> int: + return self.start_year.start_date.year + (ES_YEAR_LENGTH - 1) + + def __str__(self): + return ( + f"Engagement Strategy ({self.start_year.start_date.year}-{self.get_end_year()}) - {self.organisation.name}" + ) + + class Meta: + ordering = ("start_year",) + unique_together = ("start_year", "organisation") + verbose_name_plural = "Engagement Strategies" -- cgit v1.2.3