From fffc696fd70043252b3b956e049534dfdbf03e80 Mon Sep 17 00:00:00 2001 From: Roman Karpovich Date: Tue, 30 Jul 2024 13:53:36 +0800 Subject: [PATCH] don't include cancelled PD's into planned visits counter --- src/etools/applications/partners/models.py | 9 ++++++++- .../partners/tests/test_models.py | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/etools/applications/partners/models.py b/src/etools/applications/partners/models.py index 78b34c978..96778e241 100644 --- a/src/etools/applications/partners/models.py +++ b/src/etools/applications/partners/models.py @@ -726,7 +726,14 @@ def update_planned_visits_to_hact(self): year = datetime.date.today().year if self.partner_type != 'Government': pv = InterventionPlannedVisits.objects.filter( - intervention__agreement__partner=self, year=year).exclude(intervention__status=Intervention.DRAFT) + intervention__agreement__partner=self, + year=year, + ).exclude( + intervention__status__in=[ + Intervention.DRAFT, + Intervention.CANCELLED, + ], + ) pvq1 = pv.aggregate(models.Sum('programmatic_q1'))['programmatic_q1__sum'] or 0 pvq2 = pv.aggregate(models.Sum('programmatic_q2'))['programmatic_q2__sum'] or 0 pvq3 = pv.aggregate(models.Sum('programmatic_q3'))['programmatic_q3__sum'] or 0 diff --git a/src/etools/applications/partners/tests/test_models.py b/src/etools/applications/partners/tests/test_models.py index f0084ccbc..bf3aee700 100644 --- a/src/etools/applications/partners/tests/test_models.py +++ b/src/etools/applications/partners/tests/test_models.py @@ -399,6 +399,14 @@ def test_planned_visits_non_gov(self): agreement=self.pca_signed1, status=models.Intervention.ACTIVE ) + cancelled_intervention = InterventionFactory( + agreement=self.pca_signed1, + status=models.Intervention.CANCELLED + ) + draft_intervention = InterventionFactory( + agreement=self.pca_signed1, + status=models.Intervention.DRAFT + ) InterventionPlannedVisitsFactory( intervention=intervention, year=year - 1, @@ -410,6 +418,18 @@ def test_planned_visits_non_gov(self): programmatic_q1=1, programmatic_q3=3, ) + InterventionPlannedVisitsFactory( + intervention=draft_intervention, + year=year, + programmatic_q1=1, + programmatic_q3=3, + ) + InterventionPlannedVisitsFactory( + intervention=cancelled_intervention, + year=year, + programmatic_q1=1, + programmatic_q3=3, + ) self.partner_organization.update_planned_visits_to_hact() self.assertEqual( self.partner_organization.hact_values['programmatic_visits']['planned']['total'],