Skip to content

Commit

Permalink
Merge pull request #1496 from IFRCGo/feature/3w-add-annual-figures-1189
Browse files Browse the repository at this point in the history
Add annual figures
  • Loading branch information
szabozoltan69 authored Aug 18, 2022
2 parents 8d6ebc4 + 9b91066 commit cfcf1da
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 102 deletions.
5 changes: 5 additions & 0 deletions deployments/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class ProjectCountryFilter(AutocompleteFilter):
field_name = 'project_country'


class ProjectAnnualSplitAdminInline(admin.TabularInline):
model = models.AnnualSplit


class ProjectAdmin(CompareVersionAdmin, TranslationAdmin):
form = ProjectForm
reporting_ns_in = 'country_from__in'
Expand All @@ -113,6 +117,7 @@ class ProjectAdmin(CompareVersionAdmin, TranslationAdmin):
'user', 'reporting_ns', 'project_country', 'project_districts', 'regional_project',
'event', 'dtype',
)
inlines = [ProjectAnnualSplitAdminInline]

class Media: # Required by AutocompleteFilter
pass
Expand Down
2 changes: 1 addition & 1 deletion deployments/drf_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class ProjectViewset(
viewsets.ModelViewSet,
):
queryset = Project.objects.prefetch_related(
'user', 'reporting_ns', 'project_districts', 'event', 'dtype', 'regional_project',
'user', 'reporting_ns', 'project_districts', 'event', 'dtype', 'regional_project', 'annual_splits',
).all()
filterset_class = ProjectFilter
serializer_class = ProjectSerializer
Expand Down
33 changes: 33 additions & 0 deletions deployments/migrations/0067_annualsplit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 2.2.27 on 2022-08-18 09:43

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('deployments', '0066_auto_20220727_0708'),
]

operations = [
migrations.CreateModel(
name='AnnualSplit',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('year', models.IntegerField(blank=True, null=True, verbose_name='year')),
('budget_amount', models.IntegerField(blank=True, null=True, verbose_name='amount')),
('target_male', models.IntegerField(blank=True, null=True, verbose_name='target male')),
('target_female', models.IntegerField(blank=True, null=True, verbose_name='target female')),
('target_other', models.IntegerField(blank=True, null=True, verbose_name='target other')),
('reached_male', models.IntegerField(blank=True, null=True, verbose_name='reached male')),
('reached_female', models.IntegerField(blank=True, null=True, verbose_name='reached female')),
('reached_other', models.IntegerField(blank=True, null=True, verbose_name='reached other')),
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='annual_splits', to='deployments.Project', verbose_name='project')),
],
options={
'verbose_name': 'Annual Split',
'verbose_name_plural': 'Annual Splits',
},
),
]
21 changes: 21 additions & 0 deletions deployments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,27 @@ def get_for(user, queryset=None):
)


class AnnualSplit(models.Model):
""" Annual split for Project """

project = models.ForeignKey(Project, verbose_name=_('project'), related_name='annual_splits', on_delete=models.CASCADE)
year = models.IntegerField(verbose_name=_('year'), null=True, blank=True)
budget_amount = models.IntegerField(verbose_name=_('amount'), null=True, blank=True)
target_male = models.IntegerField(verbose_name=_('target male'), null=True, blank=True)
target_female = models.IntegerField(verbose_name=_('target female'), null=True, blank=True)
target_other = models.IntegerField(verbose_name=_('target other'), null=True, blank=True)
reached_male = models.IntegerField(verbose_name=_('reached male'), null=True, blank=True)
reached_female = models.IntegerField(verbose_name=_('reached female'), null=True, blank=True)
reached_other = models.IntegerField(verbose_name=_('reached other'), null=True, blank=True)

class Meta:
verbose_name = _('Annual Split')
verbose_name_plural = _('Annual Splits')

def __str__(self):
return '%s: %s %s | %s %s' % (str(self.project_id), str(self.year), str(self.budget_amount), str(self.target_male), str(self.reached_male),)


@reversion.register()
class ProjectImport(models.Model):
"""
Expand Down
9 changes: 9 additions & 0 deletions deployments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)

from .models import (
AnnualSplit,
ERUOwner,
ERU,
PersonnelDeployment,
Expand Down Expand Up @@ -337,6 +338,13 @@ class Meta:
fields = '__all__'


class AnnualSplitSerializer(ModelSerializer):
class Meta:
model = AnnualSplit
fields = ('year', 'budget_amount', 'target_male', 'target_female', 'target_other',
'reached_male', 'reached_female', 'reached_other',)


class ProjectSerializer(EnumSupportSerializerMixin, ModelSerializer):
project_country_detail = MiniCountrySerializer(source='project_country', read_only=True)
project_districts_detail = MiniDistrictSerializer(source='project_districts', read_only=True, many=True)
Expand All @@ -350,6 +358,7 @@ class ProjectSerializer(EnumSupportSerializerMixin, ModelSerializer):
status_display = serializers.CharField(source='get_status_display', read_only=True)
visibility_display = serializers.CharField(source='get_visibility_display', read_only=True)
secondary_sectors_display = serializers.ListField(source='get_secondary_sectors_display', read_only=True)
annual_split_detail = AnnualSplitSerializer(source='annual_splits', many=True, read_only=True)
modified_by_detail = MiniUserSerializer(source='modified_by', read_only=True)

class Meta:
Expand Down
Loading

0 comments on commit cfcf1da

Please sign in to comment.