Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [ch36775]: Amend Special Audit Export #364

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
4.7.1
----
AuditSpecial model has been extended to include the addional fields to allow export to include these changes.

4.7.0
----
* add feature that logs timestamp of access to exports
Expand Down
2 changes: 1 addition & 1 deletion src/etools_datamart/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
NAME = "etools-datamart"
VERSION = __version__ = "4.7.0"
VERSION = __version__ = "4.7.1"
__author__ = ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Generated by Django 4.2.13 on 2024-08-20 15:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("data", "0030_alter_pdindicator_baseline_denominator_and_more"),
]

operations = [
migrations.AddField(
model_name="auditspecial",
name="amount_refunded",
field=models.DecimalField(blank=True, decimal_places=2, max_digits=20, null=True),
),
migrations.AddField(
model_name="auditspecial",
name="audited_expenditure",
field=models.DecimalField(
blank=True, decimal_places=2, max_digits=20, null=True, verbose_name="Audited Expenditure $"
),
),
migrations.AddField(
model_name="auditspecial",
name="financial_findings",
field=models.DecimalField(
blank=True, decimal_places=2, max_digits=20, null=True, verbose_name="Financial Findings $"
),
),
migrations.AddField(
model_name="auditspecial",
name="justification_provided_and_accepted",
field=models.DecimalField(blank=True, decimal_places=2, max_digits=20, null=True),
),
migrations.AddField(
model_name="auditspecial",
name="pending_unsupported_amount",
field=models.DecimalField(blank=True, decimal_places=2, max_digits=20, null=True),
),
migrations.AddField(
model_name="auditspecial",
name="write_off_required",
field=models.DecimalField(
blank=True, decimal_places=2, max_digits=20, null=True, verbose_name="Impairment"
),
),
]
43 changes: 41 additions & 2 deletions src/etools_datamart/apps/mart/data/models/audit_special.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib.postgres.fields import ArrayField
from django.core.paginator import Paginator
from django.db import models
from django.db.models import JSONField
from django.db.models import JSONField, Prefetch
from django.utils.translation import gettext as _

from celery.utils.log import get_task_logger
Expand All @@ -13,7 +13,7 @@
from etools_datamart.apps.mart.data.models.audit_engagement import EngagementMixin
from etools_datamart.apps.mart.data.models.base import EtoolsDataMartModel
from etools_datamart.apps.sources.etools.enrichment.consts import AuditEngagementConsts
from etools_datamart.apps.sources.etools.models import AuditSpecialaudit, AuditSpecialauditrecommendation
from etools_datamart.apps.sources.etools.models import AuditAudit, AuditSpecialaudit, AuditSpecialauditrecommendation

from .partner import Partner

Expand All @@ -25,10 +25,18 @@ def process_country(self):
batch_size = settings.RESULTSET_BATCH_SIZE
logger.debug(f"Batch size:{batch_size}")

# TODO: Include engagement in qs
qs = AuditSpecialaudit.objects.select_related(
"engagement_ptr",
"engagement_ptr__agreement",
"engagement_ptr__agreement__auditor_firm__organization",
# "engagement_ptr__AuditAudit_engagement_ptr",
).prefetch_related(
Prefetch(
"engagement_ptr__AuditAudit_engagement_ptr",
queryset=AuditAudit.objects.all(),
to_attr="prefetched_AuditAudits",
),
)

paginator = DatamartPaginator(qs, batch_size)
Expand All @@ -44,6 +52,19 @@ def process_country(self):
self.increment_counter(op)

def get_special_procedures_count(self, record, values, field_name):
financial_findings = 0
audit = AuditAudit.objects.all().filter(engagement_ptr_id=record._impl.engagement_ptr_id)

# TODO: Retrieve financial findings from matching AuditAudit record

values["pending_unsupported_amount"] = (
financial_findings
- record.amount_refunded
- record.additional_supporting_documentation_provided
- record.justification_provided_and_accepted
- record.write_off_required
)

return AuditSpecialauditrecommendation.objects.filter(audit=record._impl).count()


Expand Down Expand Up @@ -98,6 +119,18 @@ class AuditSpecial(EtoolsDataMartModel):
action_points = JSONField(blank=True, null=True, default=dict)
action_points_data = JSONField(blank=True, null=True, default=dict)

# Extension after amendment
write_off_required = models.DecimalField("Impairment", max_digits=20, decimal_places=2, blank=True, null=True)
justification_provided_and_accepted = models.DecimalField(max_digits=20, decimal_places=2, blank=True, null=True)
amount_refunded = models.DecimalField(max_digits=20, decimal_places=2, blank=True, null=True)
pending_unsupported_amount = models.DecimalField(max_digits=20, decimal_places=2, blank=True, null=True)
audited_expenditure = models.DecimalField(
verbose_name=_("Audited Expenditure $"), blank=True, null=True, decimal_places=2, max_digits=20
)
financial_findings = models.DecimalField(
verbose_name=_("Financial Findings $"), blank=True, null=True, decimal_places=2, max_digits=20
)

loader = AuditSpecialLoader()

class Meta:
Expand All @@ -117,4 +150,10 @@ class Options:
special_procedures_count="-",
action_points="-",
action_points_data="i",
# TODO mapping for added fields that will be fetched from AuditAudit
##financial_findings="_impl.financial_findings",
##audited_expenditure="_impl.audited_expenditure",
amount_refunded="amount_refunded",
write_off_required="write_off_required",
justification_provided_and_accepted="justification_provided_and_accepted",
)