Add transactions to admin member search result
This commit is contained in:
parent
1839616aa9
commit
6c8f6f7baa
|
@ -5,6 +5,8 @@ from django.utils.timezone import now
|
|||
|
||||
from . import old_models
|
||||
|
||||
IGNORE = '+'
|
||||
|
||||
class Member(models.Model):
|
||||
user = models.OneToOneField(User, related_name='member', blank=True, null=True, on_delete=models.SET_NULL)
|
||||
old_email = models.CharField(max_length=254, blank=True, null=True)
|
||||
|
@ -38,14 +40,14 @@ class Member(models.Model):
|
|||
|
||||
class Transaction(models.Model):
|
||||
user = models.ForeignKey(User, related_name='transactions', blank=True, null=True, on_delete=models.SET_NULL)
|
||||
recorder = models.ForeignKey(User, related_name='+', blank=True, null=True, on_delete=models.SET_NULL)
|
||||
recorder = models.ForeignKey(User, related_name=IGNORE, blank=True, null=True, on_delete=models.SET_NULL)
|
||||
|
||||
member_id = models.IntegerField(blank=True, null=True)
|
||||
date = models.DateField(default=date.today)
|
||||
amount = models.DecimalField(max_digits=7, decimal_places=2)
|
||||
reference_number = models.CharField(max_length=32, blank=True, null=True)
|
||||
memo = models.TextField(blank=True, null=True)
|
||||
number_of_membership_months = models.TextField(blank=True, null=True)
|
||||
number_of_membership_months = models.IntegerField(blank=True, null=True)
|
||||
payment_method = models.TextField(blank=True, null=True)
|
||||
category = models.TextField(blank=True, null=True)
|
||||
account_type = models.TextField(blank=True, null=True)
|
||||
|
|
|
@ -80,6 +80,27 @@ class HTMLField(serializers.CharField):
|
|||
|
||||
|
||||
|
||||
class TransactionSerializer(serializers.ModelSerializer):
|
||||
account_type = serializers.ChoiceField(['Interac', 'TD Chequing', 'Paypal', 'Dream Pmt', 'PayPal', 'Square Pmt', 'Member', 'Clearing', 'Cash'])
|
||||
info_source = serializers.ChoiceField(['Web', 'DB Edit', 'System', 'Receipt or Stmt', 'Quicken Import', 'Paypal IPN', 'Auto', 'Nexus DB Bulk', 'PayPal IPN', 'IPN Trigger', 'Intranet Receipt', 'Automatic', 'Manual'])
|
||||
class Meta:
|
||||
model = models.Transaction
|
||||
fields = '__all__'
|
||||
read_only_fields = [
|
||||
'id',
|
||||
'last_seen_at',
|
||||
'user',
|
||||
'recorder',
|
||||
]
|
||||
|
||||
def create(self, validated_data):
|
||||
member = get_object_or_404(models.Member, id=validated_data['member_id'])
|
||||
if member.user:
|
||||
validated_data['user'] = member.user
|
||||
return super().create(validated_data)
|
||||
|
||||
|
||||
|
||||
# member viewing other members
|
||||
class OtherMemberSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
|
@ -163,6 +184,7 @@ class SearchSerializer(serializers.Serializer):
|
|||
class AdminSearchSerializer(serializers.Serializer):
|
||||
cards = serializers.SerializerMethodField()
|
||||
member = serializers.SerializerMethodField()
|
||||
transactions = serializers.SerializerMethodField()
|
||||
|
||||
def get_member(self, obj):
|
||||
serializer = AdminMemberSerializer(obj)
|
||||
|
@ -173,10 +195,21 @@ class AdminSearchSerializer(serializers.Serializer):
|
|||
queryset = obj.user.cards
|
||||
else:
|
||||
queryset = models.Card.objects.filter(member_id=obj.id)
|
||||
queryset = queryset.order_by('-last_seen_at')
|
||||
serializer = CardSerializer(data=queryset, many=True)
|
||||
serializer.is_valid()
|
||||
return serializer.data
|
||||
|
||||
def get_transactions(self, obj):
|
||||
if obj.user:
|
||||
queryset = obj.user.transactions
|
||||
else:
|
||||
queryset = models.Transaction.objects.filter(member_id=obj.id)
|
||||
queryset = queryset.order_by('-date')
|
||||
serializer = TransactionSerializer(data=queryset, many=True)
|
||||
serializer.is_valid()
|
||||
return serializer.data
|
||||
|
||||
|
||||
|
||||
class CardSerializer(serializers.ModelSerializer):
|
||||
|
@ -203,27 +236,6 @@ class CardSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
|
||||
class TransactionSerializer(serializers.ModelSerializer):
|
||||
account_type = serializers.ChoiceField(['Interac', 'TD Chequing', 'Paypal', 'Dream Pmt', 'PayPal', 'Square Pmt', 'Member', 'Clearing', 'Cash'])
|
||||
info_source = serializers.ChoiceField(['Web', 'DB Edit', 'System', 'Receipt or Stmt', 'Quicken Import', 'Paypal IPN', 'Auto', 'Nexus DB Bulk', 'PayPal IPN', 'IPN Trigger', 'Intranet Receipt', 'Automatic', 'Manual'])
|
||||
class Meta:
|
||||
model = models.Transaction
|
||||
fields = '__all__'
|
||||
read_only_fields = [
|
||||
'id',
|
||||
'last_seen_at',
|
||||
'user',
|
||||
'recorder',
|
||||
]
|
||||
|
||||
def create(self, validated_data):
|
||||
member = get_object_or_404(models.Member, id=validated_data['member_id'])
|
||||
if member.user:
|
||||
validated_data['user'] = member.user
|
||||
return super().create(validated_data)
|
||||
|
||||
|
||||
|
||||
class TrainingSerializer(serializers.ModelSerializer):
|
||||
attendance_status = serializers.ChoiceField(['waiting for payment', 'withdrawn', 'rescheduled', 'no-show', 'attended', 'confirmed'])
|
||||
session = serializers.PrimaryKeyRelatedField(queryset=models.Session.objects.all())
|
||||
|
|
Loading…
Reference in New Issue
Block a user