Esempio n. 1
0
    def create(self, validated_data):

        validated_data['classification'] = validated_data.get(
            'classification_id', None)
        if validated_data['classification'] is None:
            raise serializers.VilidationError('classification not found.')
        del validated_data['classification_id']

        validated_data['update_user'] = validated_data.get(
            'update_user_id', None)
        if validated_data['update_user'] is None:
            raise serializers.VilidationError('user not found.')
        del validated_data['update_user_id']

        if validated_data.get('create_user_id', None) is None:
            validated_data['create_user'] = validated_data['update_user']
        else:
            validated_data['create_user'] = validated_data.get(
                'create_user_id', None)
            if validated_data['create_user'] is None:
                raise serializers.VilidationError('user not found.')
            del validated_data['create_user_id']

        validated_data[
            'id'] = validated_data['classification'].id + validated_data.get(
                'sub_id', None)

        purpose = Purpose.objects.create(**validated_data)
        return purpose
Esempio n. 2
0
    def create(self, validated_data):

        validated_data['update_user'] = validated_data.get(
            'update_user_id', None)
        if validated_data['update_user'] is None:
            raise serializers.VilidationError('user not found.')
        del validated_data['update_user_id']

        if validated_data.get('create_user_id', None) is None:
            validated_data['create_user'] = validated_data['update_user']
        else:
            validated_data['create_user'] = validated_data.get(
                'create_user_id', None)
            if validated_data['create_user'] is None:
                raise serializers.VilidationError('user not found.')
            del validated_data['create_user_id']

        classification = Classification.objects.create(**validated_data)
        return classification
Esempio n. 3
0
    def update(self, instance, validated_data):

        instance.update_user = validated_data.get('update_user_id',
                                                  instance.update_user)
        if instance.update_user is None:
            raise serializers.VilidationError('user not found.')
        del validated_data['update_user_id']

        instance.name = validated_data.get('name', instance.name)

        instance.save()
        return instance
Esempio n. 4
0
    def create(self, validated_data):

        classification_id = validated_data.get('classification_id', None)
        sub_id = validated_data.get('sub_id', None)
        purpose_id = classification_id + sub_id
        validated_data['purpose'] = Purpose.objects.get(pk=purpose_id)
        if validated_data['purpose'] is None:
            raise serializers.VilidationError('purpose not found.')
        del validated_data['classification_id']
        del validated_data['sub_id']

        expense = Expense.objects.create(**validated_data)
        return expense
Esempio n. 5
0
    def update(self, instance, validated_data):

        classification_id = validated_data.get('classification_id', None)
        sub_id = validated_data.get('sub_id', None)
        purpose_id = classification_id + sub_id
        instance.purpose = Purpose.objects.get(pk=purpose_id)
        if instance.purpose is None:
            raise serializers.VilidationError('purpose not found.')
        del validated_data['classification_id']
        del validated_data['sub_id']

        instance.date = validated_data.get('date', instance.date)
        instance.ammount = validated_data.get('ammount', instance.ammount)
        instance.credit = validated_data.get('credit', instance.credit)

        instance.save()
        return instance