Exemplo n.º 1
0
class TPMActionPointSerializer(PermissionsBasedSerializerMixin,
                               ActionPointBaseSerializer):
    reference_number = serializers.ReadOnlyField(label=_('Reference No.'))

    partner = MinimalPartnerOrganizationListSerializer(
        read_only=True, label=_('Related Partner'))
    intervention = SeparatedReadWriteField(
        read_field=BaseInterventionListSerializer(),
        required=False,
        label=_('Related PD/SSFA'))
    cp_output = SeparatedReadWriteField(read_field=ResultSerializer(),
                                        required=False,
                                        label=_('Related CP Output'))

    location = SeparatedReadWriteField(read_field=LocationLightSerializer(),
                                       required=False,
                                       label=_('Related Location'))

    section = SeparatedReadWriteField(read_field=SectionSerializer(),
                                      required=True,
                                      label=_('Section of Assignee'))
    office = SeparatedReadWriteField(read_field=OfficeSerializer(),
                                     required=True,
                                     label=_('Office of Assignee'))

    is_responsible = serializers.SerializerMethodField()
    history = HistorySerializer(many=True,
                                label=_('History'),
                                read_only=True,
                                source='get_meaningful_history')

    url = serializers.ReadOnlyField(label=_('Link'), source='get_object_url')

    class Meta(ActionPointBaseSerializer.Meta):
        model = TPMActionPoint
        fields = ActionPointBaseSerializer.Meta.fields + [
            'partner', 'intervention', 'cp_output', 'location', 'tpm_activity',
            'section', 'office', 'history', 'is_responsible', 'url'
        ]
        fields.remove('category')
        extra_kwargs = copy(ActionPointBaseSerializer.Meta.extra_kwargs)
        extra_kwargs.update({
            'tpm_activity': {
                'label': _('Related Task')
            },
            'high_priority': {
                'label': _('Priority')
            },
        })

    def get_is_responsible(self, obj):
        return self.get_user() == obj.assigned_to

    def create(self, validated_data):
        activity = validated_data['tpm_activity']

        validated_data.update({
            'partner_id': activity.partner_id,
        })
        return super(TPMActionPointSerializer, self).create(validated_data)
Exemplo n.º 2
0
class EngagementSerializer(EngagementDatesValidation,
                           WritableNestedParentSerializerMixin,
                           EngagementListSerializer):
    staff_members = SeparatedReadWriteField(
        read_field=AuditorStaffMemberSerializer(many=True, required=False), label=_('Audit Staff Team Members')
    )
    active_pd = SeparatedReadWriteField(
        read_field=BaseInterventionListSerializer(many=True, required=False),
        label=_('Programme Document(s) or SSFA(s) - (optional)'), required=False
    )
    authorized_officers = SeparatedReadWriteField(
        read_field=PartnerStaffMemberNestedSerializer(many=True, read_only=True), label=_('Authorized Officers')
    )

    specific_procedures = SpecificProcedureSerializer(many=True, label=_('Specific Procedure To Be Performed'))

    class Meta(EngagementListSerializer.Meta):
        fields = EngagementListSerializer.Meta.fields + [
            'total_value', 'staff_members', 'active_pd',
            'authorized_officers',

            'joint_audit', 'shared_ip_with', 'exchange_rate',

            'start_date', 'end_date',
            'partner_contacted_at', 'date_of_field_visit',
            'date_of_draft_report_to_ip', 'date_of_comments_by_ip',
            'date_of_draft_report_to_unicef', 'date_of_comments_by_unicef',
            'date_of_report_submit', 'date_of_final_report', 'date_of_cancel',
            'cancel_comment', 'specific_procedures',
        ]
        extra_kwargs = {
            field: {'required': True} for field in [
                'start_date', 'end_date', 'total_value',

                'partner_contacted_at',
                'date_of_field_visit',
                'date_of_draft_report_to_ip',
                'date_of_comments_by_ip',
                'date_of_draft_report_to_unicef',
                'date_of_comments_by_unicef',
            ]
        }
        extra_kwargs['engagement_type'] = {'label': _('Engagement Type')}

    def validate(self, data):
        validated_data = super().validate(data)
        staff_members = validated_data.get('staff_members', [])
        validated_data.pop('related_agreement', None)
        agreement = validated_data.get('agreement', None) or self.instance.agreement if self.instance else None

        if staff_members and agreement and agreement.auditor_firm:
            existed_staff_members = agreement.auditor_firm.staff_members.all()
            unexisted = set(staff_members) - set(existed_staff_members)
            if unexisted:
                msg = self.fields['staff_members'].write_field.child_relation.error_messages['does_not_exist']
                raise serializers.ValidationError({
                    'staff_members': [msg.format(pk_value=staff_member.pk) for staff_member in unexisted],
                })

        return validated_data
Exemplo n.º 3
0
class EngagementActionPointSerializer(PermissionsBasedSerializerMixin,
                                      ActionPointBaseSerializer):
    reference_number = serializers.ReadOnlyField(label=_('Reference No.'))

    partner = MinimalPartnerOrganizationListSerializer(
        read_only=True, label=_('Related Partner'))
    intervention = SeparatedReadWriteField(
        label=_('Related PD/SSFA'),
        read_field=BaseInterventionListSerializer(),
        required=False,
    )

    section = SeparatedReadWriteField(
        read_field=SectionSerializer(read_only=True),
        required=True,
        label=_('Section of Assignee'))
    office = SeparatedReadWriteField(
        read_field=OfficeSerializer(read_only=True),
        required=True,
        label=_('Office of Assignee'))
    category = CategoryModelChoiceField(
        label=_('Action Point Category'),
        required=True,
        queryset=Category.objects.filter(module=Category.MODULE_CHOICES.audit))

    history = HistorySerializer(many=True,
                                label=_('History'),
                                read_only=True,
                                source='get_meaningful_history')

    url = serializers.ReadOnlyField(label=_('Link'), source='get_object_url')

    class Meta(ActionPointBaseSerializer.Meta):
        model = EngagementActionPoint
        fields = ActionPointBaseSerializer.Meta.fields + [
            'partner',
            'intervention',
            'history',
            'url',
        ]
        extra_kwargs = copy(ActionPointBaseSerializer.Meta.extra_kwargs)
        extra_kwargs.update({
            'high_priority': {
                'label': _('Priority')
            },
        })

    def create(self, validated_data):
        engagement = validated_data['engagement']
        validated_data.update({
            'partner_id': engagement.partner_id,
        })

        return super().create(validated_data)
Exemplo n.º 4
0
class ActionPointListSerializer(PermissionsBasedSerializerMixin,
                                ActionPointBaseSerializer):
    related_module = serializers.ChoiceField(
        label=_('Related App'),
        choices=ActionPoint.MODULE_CHOICES,
        read_only=True)

    partner = SeparatedReadWriteField(
        read_field=MinimalPartnerOrganizationListSerializer(
            read_only=True, label=_('Partner')), )
    intervention = SeparatedReadWriteField(
        read_field=BaseInterventionListSerializer(read_only=True,
                                                  label=_('PD/SSFA')),
        required=False,
    )

    cp_output = SeparatedReadWriteField(
        read_field=ResultSerializer(read_only=True, label=_('CP Output')),
        required=False,
    )

    location = SeparatedReadWriteField(read_field=LocationLightSerializer(
        read_only=True, label=_('Location')), )

    section = SeparatedReadWriteField(
        read_field=SectionSerializer(read_only=True,
                                     label=_('Section of Assignee')),
        required=True,
    )
    office = SeparatedReadWriteField(read_field=OfficeSerializer(
        read_only=True, label=_('Office of Assignee')),
                                     required=True)

    class Meta(ActionPointBaseSerializer.Meta):
        fields = ActionPointBaseSerializer.Meta.fields + [
            'related_module',
            'cp_output',
            'partner',
            'intervention',
            'location',
            'engagement',
            'tpm_activity',
            'travel_activity',
        ]