diff --git a/CHANGES b/CHANGES index 552ddb37d..de9d9ab23 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/src/etools_datamart/__init__.py b/src/etools_datamart/__init__.py index 06cc35123..236f19de2 100644 --- a/src/etools_datamart/__init__.py +++ b/src/etools_datamart/__init__.py @@ -1,3 +1,3 @@ NAME = "etools-datamart" -VERSION = __version__ = "4.7.0" +VERSION = __version__ = "4.7.1" __author__ = "" diff --git a/src/etools_datamart/apps/mart/data/migrations/0031_auditspecial_amount_refunded_and_more.py b/src/etools_datamart/apps/mart/data/migrations/0031_auditspecial_amount_refunded_and_more.py new file mode 100644 index 000000000..199896f98 --- /dev/null +++ b/src/etools_datamart/apps/mart/data/migrations/0031_auditspecial_amount_refunded_and_more.py @@ -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" + ), + ), + ] diff --git a/src/etools_datamart/apps/mart/data/models/audit_special.py b/src/etools_datamart/apps/mart/data/models/audit_special.py index e0cd3fe4d..7c98dadcf 100644 --- a/src/etools_datamart/apps/mart/data/models/audit_special.py +++ b/src/etools_datamart/apps/mart/data/models/audit_special.py @@ -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 @@ -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 @@ -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) @@ -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() @@ -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: @@ -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", )