Пример #1
0
def set_activity_aggregations(activity):
    """
    set total activity aggregations for the different transaction types and
    budget
    """
    aac = ActivityAggregationCalculation()
    aac.parse_activity_aggregations(activity)
Пример #2
0
    def save_formset(self, request, form, formset, change):
        if formset.model == Narrative:
            for entry in formset.cleaned_data:
                if entry and entry['id'] is None:
                    if isinstance(formset.instance, DocumentLinkTitle):
                        formset.instance.document_link_id = formset\
                            .instance.document_link.id
                        formset.instance.save()
                    entry['activity'] = self.act

        super(ActivityAdmin, self).save_formset(request, form, formset, change)

        # set derived activity dates (used for sorting)
        if formset.model == ActivityDate:

            activity = form.instance
            for ad in activity.activitydate_set.all():
                if ad.type.code == '1':
                    activity.planned_start = ad.iso_date
                if ad.type.code == '2':
                    activity.actual_start = ad.iso_date
                if ad.type.code == '3':
                    activity.planned_end = ad.iso_date
                if ad.type.code == '4':
                    activity.actual_end = ad.iso_date

            if activity.actual_start:
                activity.start_date = activity.actual_start
            else:
                activity.start_date = activity.planned_start

            if activity.actual_end:
                activity.end_date = activity.actual_end
            else:
                activity.end_date = activity.planned_end
            activity.save()

        # save primary name on participating organisation to make querying work
        if isinstance(formset.instance, ActivityParticipatingOrganisation):
            if formset.cleaned_data[0]:
                po = formset.instance
                if po.narratives.all().count() > 0:
                    po.primary_name = po.narratives.all()[0].content.strip()
                    po.save()

        # update aggregations after save of last inline form
        if formset.model == Transaction:
            aggregation_calculator = ActivityAggregationCalculation()
            aggregation_calculator.parse_activity_aggregations(form.instance)
Пример #3
0
    def save_formset(self, request, form, formset, change):
        if formset.model == Narrative:
            for entry in formset.cleaned_data:
                if entry and entry['id'] is None:
                    entry['activity'] = self.act

        super(TransactionAdmin, self).save_formset(request, form, formset,
                                                   change)

        if formset.model == TransactionDescription:
            try:
                if formset.instance.description.id is None:
                    formset.instance.description.save()
            except ObjectDoesNotExist:
                pass

        if formset.model == TransactionProvider:
            try:
                if formset.instance.provider_organisation.id is None:
                    formset.instance.provider_organisation.save()
            except ObjectDoesNotExist:
                pass

        if isinstance(formset.instance, TransactionProvider):
            if formset.cleaned_data[0]:
                tp = formset.instance
                if tp.narratives.all().count() > 0:
                    tp.primary_name = tp.narratives.all()[0].content.strip()
                    tp.save()

        if isinstance(formset.instance, TransactionReceiver):
            if formset.cleaned_data[0]:
                tr = formset.instance
                if tr.narratives.all().count() > 0:
                    tr.primary_name = tr.narratives.all()[0].content.strip()
                    tr.save()

        # update aggregations after save of last inline form
        if formset.model == TransactionReceiver:
            try:
                if formset.instance.receiver_organisation.id is None:
                    formset.instance.receiver_organisation.save()
            except ObjectDoesNotExist:
                pass

            aggregation_calculator = ActivityAggregationCalculation()
            aggregation_calculator.parse_activity_aggregations(
                form.instance.activity)
Пример #4
0
def calculate_activity_aggregations_per_source(source_ref):
    aac = ActivityAggregationCalculation()
    aac.parse_activity_aggregations_by_source(source_ref)
Пример #5
0
def calculate_activity_aggregations_per_source(source_ref):
    aac = ActivityAggregationCalculation()
    aac.parse_activity_aggregations_by_source(source_ref)