Skip to content

Commit

Permalink
Merge pull request #2428 from unicef/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
domdinicola authored Jul 3, 2019
2 parents dde43ec + a6ecaac commit 636a98e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
22 changes: 15 additions & 7 deletions src/etools/applications/hact/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django.contrib.postgres.fields import JSONField
from django.db import models
from django.db.models import Count, Sum
from django.db.models import Count, Q, Sum
from django.db.models.functions import Coalesce
from django.utils.translation import ugettext_lazy as _

Expand Down Expand Up @@ -210,8 +210,9 @@ def get_cash_transfer_partner_type(self):

@staticmethod
def get_spot_checks_completed():
qs = SpotCheck.objects.filter(date_of_draft_report_to_ip__year=datetime.now().year).exclude(
status=Engagement.CANCELLED)
qs = SpotCheck.objects.filter(
Q(partner__reported_cy__gt=0) | Q(partner__total_ct_cy__gt=0), partner__hidden=False,
date_of_draft_report_to_ip__year=datetime.now().year).exclude(status=Engagement.CANCELLED)
return [
['Completed by', 'Count'],
['Staff', qs.filter(agreement__auditor_firm__unicef_users_allowed=True).count()],
Expand All @@ -227,19 +228,23 @@ def get_assurance_activities(self):
},
'spot_checks': {
'completed': SpotCheck.objects.filter(
Q(partner__reported_cy__gt=0) | Q(partner__total_ct_cy__gt=0), partner__hidden=False,
date_of_draft_report_to_ip__year=datetime.now().year).exclude(
status=Engagement.CANCELLED).count(),
'min_required': sum([p.min_req_spot_checks for p in self.get_queryset()]),
'follow_up': self.get_queryset().aggregate(total=Coalesce(Sum(
'planned_engagement__spot_check_follow_up'), 0))['total']
},
'scheduled_audit': Audit.objects.filter(
Q(partner__reported_cy__gt=0) | Q(partner__total_ct_cy__gt=0), partner__hidden=False,
date_of_draft_report_to_ip__year=datetime.now().year).exclude(
status=Engagement.CANCELLED).count(),
'special_audit': SpecialAudit.objects.filter(
Q(partner__reported_cy__gt=0) | Q(partner__total_ct_cy__gt=0), partner__hidden=False,
date_of_draft_report_to_ip__year=datetime.now().year).exclude(
status=Engagement.CANCELLED).count(),
'micro_assessment': MicroAssessment.objects.filter(
Q(partner__reported_cy__gt=0) | Q(partner__total_ct_cy__gt=0), partner__hidden=False,
date_of_draft_report_to_ip__year=datetime.now().year).exclude(
status=Engagement.CANCELLED).count(),
'missing_micro_assessment': PartnerOrganization.objects.hact_active(
Expand All @@ -248,8 +253,9 @@ def get_assurance_activities(self):

@staticmethod
def get_financial_findings():
audits = Audit.objects.filter(date_of_draft_report_to_ip__year=datetime.now().year).exclude(
status=Engagement.CANCELLED)
audits = Audit.objects.filter(
Q(partner__reported_cy__gt=0) | Q(partner__total_ct_cy__gt=0), partner__hidden=False,
date_of_draft_report_to_ip__year=datetime.now().year).exclude(status=Engagement.CANCELLED)

refunds = audits.filter(amount_refunded__isnull=False).aggregate(
total=Coalesce(Sum('amount_refunded'), 0))['total']
Expand All @@ -276,6 +282,7 @@ def get_financial_findings():
outstanding = _ff - _ar - _asdp - _wor

outstanding_audits_y1 = Audit.objects.filter(
Q(partner__reported_cy__gt=0) | Q(partner__total_ct_cy__gt=0), partner__hidden=False,
date_of_draft_report_to_ip__year=datetime.now().year - 1).exclude(status=Engagement.CANCELLED)
_ff_y1 = outstanding_audits_y1.filter(financial_findings__isnull=False).aggregate(
total=Coalesce(Sum('financial_findings'), 0))['total']
Expand Down Expand Up @@ -338,8 +345,9 @@ def get_financial_findings():
@staticmethod
def get_financial_findings_numbers():

audits = Audit.objects.filter(date_of_draft_report_to_ip__year=datetime.now().year).exclude(
status=Engagement.CANCELLED)
audits = Audit.objects.filter(
Q(partner__reported_cy__gt=0) | Q(partner__total_ct_cy__gt=0), partner__hidden=False,
date_of_draft_report_to_ip__year=datetime.now().year).exclude(status=Engagement.CANCELLED)
return [
{
'name': 'Number of High Priority Findings',
Expand Down
22 changes: 15 additions & 7 deletions src/etools/applications/hact/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def setUpTestData(cls):
amount_refunded=400000.0,
audited_expenditure=50.0,
financial_findings=999.0,
partner__reported_cy=550000.0,
)

AuditFactory(
Expand All @@ -68,6 +69,7 @@ def setUpTestData(cls):
amount_refunded=40.0,
audited_expenditure=50.0,
financial_findings=100.0,
partner__reported_cy=550000.0,
)

def test_cash_transfers_amounts(self):
Expand All @@ -94,11 +96,11 @@ def test_get_cash_transfer_partner_type(self):

def test_get_spot_checks_completed(self):
SpotCheckFactory(
status=Engagement.FINAL, date_of_draft_report_to_ip=datetime(datetime.today().year, 12, 5))
partner__reported_cy=550000.0, status=Engagement.FINAL, date_of_draft_report_to_ip=datetime(datetime.today().year, 12, 5))
SpotCheckFactory(
status=Engagement.FINAL, date_of_draft_report_to_ip=datetime(datetime.today().year - 1, 12, 5))
partner__reported_cy=550000.0, status=Engagement.FINAL, date_of_draft_report_to_ip=datetime(datetime.today().year - 1, 12, 5))
SpotCheckFactory(
status=Engagement.FINAL,
partner__reported_cy=550000.0, status=Engagement.FINAL,
date_of_draft_report_to_ip=datetime(datetime.today().year, 6, 3),
agreement__auditor_firm__unicef_users_allowed=True)
SpotCheckFactory(
Expand All @@ -111,17 +113,20 @@ def test_get_spot_checks_completed(self):

def test_get_assurance_activities(self):
SpecialAuditFactory(
status=Engagement.FINAL, date_of_draft_report_to_ip=datetime(datetime.today().year, 2, 3))
partner__reported_cy=550000.0, status=Engagement.FINAL,
date_of_draft_report_to_ip=datetime(datetime.today().year, 2, 3))
SpecialAuditFactory(
status=Engagement.FINAL, date_of_draft_report_to_ip=datetime(datetime.today().year - 1, 2, 3))
partner__reported_cy=550000.0, status=Engagement.FINAL,
date_of_draft_report_to_ip=datetime(datetime.today().year - 1, 2, 3))
MicroAssessmentFactory(
status=Engagement.FINAL, date_of_draft_report_to_ip=datetime(datetime.today().year, 8, 10))
partner__reported_cy=550000.0, status=Engagement.FINAL,
date_of_draft_report_to_ip=datetime(datetime.today().year, 8, 10))
assurance_activities = self.aggregate_hact.get_assurance_activities()
self.assertEqual(len(list(assurance_activities.keys())), 6)
self.assertEqual(assurance_activities['programmatic_visits']['completed'], 0)
self.assertEqual(assurance_activities['programmatic_visits']['min_required'], 5)
self.assertEqual(assurance_activities['spot_checks']['completed'], 0)
self.assertEqual(assurance_activities['spot_checks']['min_required'], 1)
self.assertEqual(assurance_activities['spot_checks']['min_required'], 6)
self.assertEqual(assurance_activities['scheduled_audit'], 1)
self.assertEqual(assurance_activities['special_audit'], 1)
self.assertEqual(assurance_activities['micro_assessment'], 1)
Expand Down Expand Up @@ -153,6 +158,7 @@ def _check_item(financial_dict_item, name, value):
RiskFactory(
value=4,
engagement=AuditFactory(
partner__reported_cy=550000.0,
status=Engagement.FINAL,
audit_opinion=Audit.OPTION_QUALIFIED,
date_of_draft_report_to_ip=datetime(datetime.today().year, 1, 3),
Expand All @@ -161,6 +167,7 @@ def _check_item(financial_dict_item, name, value):
RiskFactory(
value=2,
engagement=AuditFactory(
partner__reported_cy=550000.0,
status=Engagement.REPORT_SUBMITTED,
audit_opinion=Audit.OPTION_ADVERSE,
date_of_draft_report_to_ip=datetime(datetime.today().year - 1, 4, 7),
Expand All @@ -169,6 +176,7 @@ def _check_item(financial_dict_item, name, value):
RiskFactory(
value=1,
engagement=AuditFactory(
partner__reported_cy=550000.0,
status=Engagement.PARTNER_CONTACTED,
audit_opinion=Audit.OPTION_DENIAL,
date_of_draft_report_to_ip=datetime(datetime.today().year - 1, 4, 7),
Expand Down

0 comments on commit 636a98e

Please sign in to comment.