Skip to content

Commit

Permalink
Merge branch 'feature/3w-add-annual-figures-1189' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
szabozoltan69 committed Aug 30, 2022
2 parents caafd1a + cf79036 commit 90b7f45
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 16 additions & 0 deletions deployments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,22 @@ def get_secondary_sectors_display(self):
]

def save(self, *args, **kwargs):

if hasattr(self, 'annual_split_detail') and self.annual_split_detail:
for split in self.annual_split_detail:
annual_split = AnnualSplit.objects.get(pk=split['id'])
annual_split.year = split['year'] if 'year' in split else None
annual_split.budget_amount = split['budget_amount'] if 'budget_amount' in split else None
annual_split.target_male = split['target_male'] if 'target_male' in split else None
annual_split.target_female = split['target_female'] if 'target_female' in split else None
annual_split.target_other = split['target_other'] if 'target_other' in split else None
annual_split.target_total = split['target_total'] if 'target_total' in split else None
annual_split.reached_male = split['reached_male'] if 'reached_male' in split else None
annual_split.reached_female = split['reached_female'] if 'reached_female' in split else None
annual_split.reached_other = split['reached_other'] if 'reached_other' in split else None
annual_split.reached_total = split['reached_total'] if 'reached_total' in split else None
annual_split.save()

# Automatically assign status according to the start_date and end_date
# Cronjob will change the status automatically in future
now = timezone.now().date()
Expand Down
4 changes: 3 additions & 1 deletion deployments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class AnnualSplitSerializer(ModelSerializer):
class Meta:
model = AnnualSplit
fields = (
'year', 'budget_amount',
'id', 'year', 'budget_amount', # id: needed for appropriate update
'target_male', 'target_female', 'target_other', 'target_total',
'reached_male', 'reached_female', 'reached_other', 'reached_total',
)
Expand Down Expand Up @@ -377,6 +377,8 @@ class Meta:
}

def validate(self, data):
if self.context and 'request' in self.context:
data['annual_split_detail'] = self.context['request'].data.get('annual_split_detail')
d_project_districts = data['project_districts']
# Override country with district's country
if isinstance(d_project_districts, list) and len(d_project_districts):
Expand Down

0 comments on commit 90b7f45

Please sign in to comment.