Skip to content

Commit 90b7f45

Browse files
committed
Merge branch 'feature/3w-add-annual-figures-1189' into develop
2 parents caafd1a + cf79036 commit 90b7f45

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

deployments/models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,22 @@ def get_secondary_sectors_display(self):
494494
]
495495

496496
def save(self, *args, **kwargs):
497+
498+
if hasattr(self, 'annual_split_detail') and self.annual_split_detail:
499+
for split in self.annual_split_detail:
500+
annual_split = AnnualSplit.objects.get(pk=split['id'])
501+
annual_split.year = split['year'] if 'year' in split else None
502+
annual_split.budget_amount = split['budget_amount'] if 'budget_amount' in split else None
503+
annual_split.target_male = split['target_male'] if 'target_male' in split else None
504+
annual_split.target_female = split['target_female'] if 'target_female' in split else None
505+
annual_split.target_other = split['target_other'] if 'target_other' in split else None
506+
annual_split.target_total = split['target_total'] if 'target_total' in split else None
507+
annual_split.reached_male = split['reached_male'] if 'reached_male' in split else None
508+
annual_split.reached_female = split['reached_female'] if 'reached_female' in split else None
509+
annual_split.reached_other = split['reached_other'] if 'reached_other' in split else None
510+
annual_split.reached_total = split['reached_total'] if 'reached_total' in split else None
511+
annual_split.save()
512+
497513
# Automatically assign status according to the start_date and end_date
498514
# Cronjob will change the status automatically in future
499515
now = timezone.now().date()

deployments/serializers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class AnnualSplitSerializer(ModelSerializer):
342342
class Meta:
343343
model = AnnualSplit
344344
fields = (
345-
'year', 'budget_amount',
345+
'id', 'year', 'budget_amount', # id: needed for appropriate update
346346
'target_male', 'target_female', 'target_other', 'target_total',
347347
'reached_male', 'reached_female', 'reached_other', 'reached_total',
348348
)
@@ -377,6 +377,8 @@ class Meta:
377377
}
378378

379379
def validate(self, data):
380+
if self.context and 'request' in self.context:
381+
data['annual_split_detail'] = self.context['request'].data.get('annual_split_detail')
380382
d_project_districts = data['project_districts']
381383
# Override country with district's country
382384
if isinstance(d_project_districts, list) and len(d_project_districts):

0 commit comments

Comments
 (0)