diff --git a/src/etools/applications/partners/migrations/0121_auto_20230607_0736.py b/src/etools/applications/partners/migrations/0121_auto_20230607_1523.py similarity index 87% rename from src/etools/applications/partners/migrations/0121_auto_20230607_0736.py rename to src/etools/applications/partners/migrations/0121_auto_20230607_1523.py index 4ed75ea53..d9b6c6321 100644 --- a/src/etools/applications/partners/migrations/0121_auto_20230607_0736.py +++ b/src/etools/applications/partners/migrations/0121_auto_20230607_1523.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.6 on 2023-06-07 07:36 +# Generated by Django 3.2.6 on 2023-06-07 15:23 from django.db import migrations, models @@ -15,6 +15,11 @@ class Migration(migrations.Migration): name='has_unfunded_cash', field=models.BooleanField(default=False, verbose_name='Unfunded Cash'), ), + migrations.AddField( + model_name='interventionbudget', + name='total_unfunded', + field=models.DecimalField(decimal_places=2, default=0, max_digits=20, verbose_name='Total Unfunded'), + ), migrations.AddField( model_name='interventionbudget', name='unfunded_cash_local', diff --git a/src/etools/applications/partners/models.py b/src/etools/applications/partners/models.py index e4be1415a..4fbf967a1 100644 --- a/src/etools/applications/partners/models.py +++ b/src/etools/applications/partners/models.py @@ -3079,7 +3079,7 @@ class InterventionBudget(TimeStampedModel): verbose_name=_('UNICEF Supplies') ) total = models.DecimalField(max_digits=20, decimal_places=2, verbose_name=_('Total')) - total_unfunded = models.DecimalField(max_digits=20, decimal_places=2, verbose_name=_('Total Unfunded')) + total_unfunded = models.DecimalField(max_digits=20, decimal_places=2, default=0, verbose_name=_('Total Unfunded')) # sum of all activity/management budget cso/partner values partner_contribution_local = models.DecimalField(max_digits=20, decimal_places=2, default=0, @@ -3700,9 +3700,13 @@ def partner_total(self): def unicef_total(self): return self.act1_unicef + self.act2_unicef + self.act3_unicef + @property + def unfunded_total(self): + return self.act1_unfunded + self.act2_unfunded + self.act3_unfunded + @property def total(self): - return self.partner_total + self.unicef_total + return self.partner_total + self.unicef_total + self.unfunded_total def save(self, *args, **kwargs): create = not self.pk @@ -3714,17 +3718,22 @@ def save(self, *args, **kwargs): def update_cash(self): aggregated_items = self.items.values('kind').order_by('kind') - aggregated_items = aggregated_items.annotate(unicef_cash=Sum('unicef_cash'), cso_cash=Sum('cso_cash')) + aggregated_items = aggregated_items.annotate( + unicef_cash=Sum('unicef_cash'), cso_cash=Sum('cso_cash'), unfunded_cash=Sum('unfunded_cash') + ) for item in aggregated_items: if item['kind'] == InterventionManagementBudgetItem.KIND_CHOICES.in_country: self.act1_unicef = item['unicef_cash'] self.act1_partner = item['cso_cash'] + self.act1_unfunded = item['unfunded_cash'] elif item['kind'] == InterventionManagementBudgetItem.KIND_CHOICES.operational: self.act2_unicef = item['unicef_cash'] self.act2_partner = item['cso_cash'] + self.act2_unfunded = item['unfunded_cash'] elif item['kind'] == InterventionManagementBudgetItem.KIND_CHOICES.planning: self.act3_unicef = item['unicef_cash'] self.act3_partner = item['cso_cash'] + self.act3_unfunded = item['unfunded_cash'] self.save() diff --git a/src/etools/applications/partners/serializers/interventions_v3.py b/src/etools/applications/partners/serializers/interventions_v3.py index e3ecf955f..e5aad5687 100644 --- a/src/etools/applications/partners/serializers/interventions_v3.py +++ b/src/etools/applications/partners/serializers/interventions_v3.py @@ -191,6 +191,7 @@ class InterventionManagementBudgetSerializer( act3_total = serializers.SerializerMethodField() partner_total = serializers.DecimalField(max_digits=20, decimal_places=2, read_only=True) unicef_total = serializers.DecimalField(max_digits=20, decimal_places=2, read_only=True) + unfunded_total = serializers.DecimalField(max_digits=20, decimal_places=2, read_only=True) total = serializers.DecimalField(max_digits=20, decimal_places=2, read_only=True) class Meta: @@ -199,12 +200,15 @@ class Meta: "items", "act1_unicef", "act1_partner", + "act1_unfunded", "act1_total", "act2_unicef", "act2_partner", + "act2_unfunded", "act2_total", "act3_unicef", "act3_partner", + "act3_unfunded", "act3_total", "partner_total", "unicef_total", @@ -212,13 +216,13 @@ class Meta: ) def get_act1_total(self, obj): - return str(obj.act1_unicef + obj.act1_partner) + return str(obj.act1_unicef + obj.act1_partner + obj.act1_unfunded) def get_act2_total(self, obj): - return str(obj.act2_unicef + obj.act2_partner) + return str(obj.act2_unicef + obj.act2_partner + obj.act2_unfunded) def get_act3_total(self, obj): - return str(obj.act3_unicef + obj.act3_partner) + return str(obj.act3_unicef + obj.act3_partner + obj.act3_unfunded) @transaction.atomic def update(self, instance, validated_data):