# Path: api_v3/models/expense.py
# class Expense(models.Model):
#     """Ticket expense model."""
# 
#     ticket = models.ForeignKey(
#         Ticket, blank=False, related_name='expenses', db_index=True,
#         on_delete=models.DO_NOTHING)
#     user = models.ForeignKey(
#         settings.AUTH_USER_MODEL, blank=False, db_index=True,
#         on_delete=models.DO_NOTHING)
# 
#     amount = MoneyField(
#         max_digits=19, decimal_places=4, null=True,
#         default_currency=CURRENCIES['USD'].code)
# 
#     rating = models.IntegerField(default=0)
#     scope = models.CharField(max_length=255, blank=False, null=False)
#     payment_method = models.CharField(max_length=255, null=True, blank=True)
#     notes = models.TextField(blank=True, null=True)
#     created_at = models.DateTimeField(default=datetime.utcnow)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     @classmethod
#     def filter_by_user(cls, user, queryset=None):
#         """Returns any user accessible expenses.
# 
#         Only ticket responders have access to the expenses.
#         """
#         if queryset is None:
#             queryset = cls.objects
# 
#         return queryset.filter(ticket__responder_users=user)


from rest_framework_json_api import serializers
from api_v3.models import Expense



class ExpenseSerializer(serializers.ModelSerializer):

    included_serializers = {
        'user': 'api_v3.serializers.ProfileSerializer',
        'ticket': 'api_v3.serializers.TicketSerializer'
    }

    class Meta:
        model = Expense
        read_only_fields = ('user', 'updated_at')
        fields = (
            'id',
            'user',
            'ticket',
            'amount',
            'amount_currency',
            'rating',

# Path: api_v3/models/expense.py
# class Expense(models.Model):
#     """Ticket expense model."""
# 
#     ticket = models.ForeignKey(
#         Ticket, blank=False, related_name='expenses', db_index=True,
#         on_delete=models.DO_NOTHING)
#     user = models.ForeignKey(
#         settings.AUTH_USER_MODEL, blank=False, db_index=True,
#         on_delete=models.DO_NOTHING)
# 
#     amount = MoneyField(
#         max_digits=19, decimal_places=4, null=True,
#         default_currency=CURRENCIES['USD'].code)
# 
#     rating = models.IntegerField(default=0)
#     scope = models.CharField(max_length=255, blank=False, null=False)
#     payment_method = models.CharField(max_length=255, null=True, blank=True)
#     notes = models.TextField(blank=True, null=True)
#     created_at = models.DateTimeField(default=datetime.utcnow)
#     updated_at = models.DateTimeField(auto_now=True)
# 
#     @classmethod
#     def filter_by_user(cls, user, queryset=None):
#         """Returns any user accessible expenses.
# 
#         Only ticket responders have access to the expenses.
#         """
#         if queryset is None:
#             queryset = cls.objects
# 
#         return queryset.filter(ticket__responder_users=user)


# Path: api_v3/serializers/expense.py
from rest_framework_json_api import serializers
from api_v3.models import Expense




class ExpenseSerializer(serializers.ModelSerializer):

    included_serializers = {
        'user': 'api_v3.serializers.ProfileSerializer',
        'ticket': 'api_v3.serializers.TicketSerializer'
    }

    class Meta:
        model = Expense
        read_only_fields = ('user', 'updated_at')
        fields = (
            'id',
            'user',
            'ticket',
            'amount',
            'amount_currency',
            'rating',

            'notes',