Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
amschaal committed Jan 22, 2020
1 parent 37b49f4 commit 8268b6e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
12 changes: 12 additions & 0 deletions ezreg/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,24 @@ class RefundSerializer(serializers.ModelSerializer):
registrant = serializers.SerializerMethodField()
event = serializers.SerializerMethodField()
event_id = serializers.SerializerMethodField()
external_id = serializers.SerializerMethodField()
admin = serializers.SerializerMethodField()
requester = serializers.SerializerMethodField()
paid = serializers.SerializerMethodField()
def get_event(self, obj):
return obj.registration.event.title
def get_event_id(self, obj):
return obj.registration.event_id
def get_external_id(self, obj):
return getattr(getattr(obj.registration,'payment',None),'external_id',None)
def get_paid(self, obj):
return getattr(getattr(obj.registration,'payment',None),'amount',None)
def get_registrant(self, obj):
return '{}, {} ({})'.format(obj.registration.last_name,obj.registration.first_name,obj.registration.email)
def get_admin(self, obj):
return obj.admin.display() if obj.admin else ''
def get_requester(self, obj):
return obj.requester.display() if obj.requester else ''
class Meta:
model = Refund
exclude = []
Expand Down
8 changes: 6 additions & 2 deletions ezreg/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ def get_queryset(self):
class RefundViewset(viewsets.ReadOnlyModelViewSet):
# queryset = MailerMessage.objects.all().prefetch_related('registrations')
filter_backends = viewsets.ReadOnlyModelViewSet.filter_backends + [OrFilter]
or_filters = {'registrant':['registration__first_name__icontains', 'registration__last_name__icontains', 'registration__email__icontains']}
or_filters = {
'registrant':['registration__first_name__icontains', 'registration__last_name__icontains', 'registration__email__icontains'],
'admin':['admin__first_name__icontains', 'admin__last_name__icontains', 'admin__email__icontains'],
'requester':['requester__first_name__icontains', 'requester__last_name__icontains', 'requester__email__icontains']
}
serializer_class = RefundSerializer
filter_fields = {'registration__id':['exact'],'registration__event':['exact'],'status':['exact','icontains'],'registration__payment__external_id':['icontains'],'registration__payment__external_id':['icontains'],'status':['icontains'],'registration__event__title':['icontains']}
ordering_fields = ['requested','status','registration__event__title']
ordering_fields = ['requested','status','amount','updated','registration__event__title','registration__payment__external_id']
def get_queryset(self):
if self.request.user.is_staff:
qs = Refund.objects.all()
Expand Down
3 changes: 2 additions & 1 deletion ezreg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,5 +413,6 @@ def save_event_ical(sender,instance,**kwargs):
pre_save.connect(save_event_ical, sender=Event)

def user_display(self):
return '{}, {} ({})'.format(self.last_name, self.first_name, self.email)
return '{}, {}'.format(self.last_name, self.first_name)
# return '{}, {} ({})'.format(self.last_name, self.first_name, self.email)
User.display = user_display
34 changes: 18 additions & 16 deletions ezreg/static/ezreg/js/pages/refunds.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,26 @@ function RefundsController($scope,$http,growl,DRFNgTableParams) {
$scope.registrationLink = function(registration){return django_js_utils.urls.resolve('registration', { id: registration })};
$scope.eventLink = function(event){return django_js_utils.urls.resolve('manage_event', { event: event })};
$scope.complete = function (refund) {
$http.post('/api/refunds/'+refund.id+'/complete/',{}).then(function(response){
growl.success('Refund set as completed' ,{ttl: 5000});
$scope.tableParams.reload();
}, function(response){
if (response.data.detail)
growl.error(response.data.detail ,{ttl: 5000});
});

if (confirm('Are you sure you want to complete this refund? This action cannot be undone.')){
$http.post('/api/refunds/'+refund.id+'/complete/',{}).then(function(response){
growl.success('Refund set as completed' ,{ttl: 5000});
$scope.tableParams.reload();
}, function(response){
if (response.data.detail)
growl.error(response.data.detail ,{ttl: 5000});
});
}
};
$scope.cancel = function (refund) {
$http.post('/api/refunds/'+refund.id+'/cancel/',{}).then(function(response){
growl.success('Refund cancelled' ,{ttl: 5000});
$scope.tableParams.reload();
}, function(response){
if (response.data.detail)
growl.error(response.data.detail ,{ttl: 5000});
});

if (confirm('Are you sure you want to cancel this refund? This action cannot be undone.')){
$http.post('/api/refunds/'+refund.id+'/cancel/',{}).then(function(response){
growl.success('Refund cancelled' ,{ttl: 5000});
$scope.tableParams.reload();
}, function(response){
if (response.data.detail)
growl.error(response.data.detail ,{ttl: 5000});
});
}
};
// $scope.tableParams = DRFNgTableParams('/api/emails/',{sorting: { last_attempt: "desc" }});
}
Expand Down
6 changes: 6 additions & 0 deletions ezreg/templates/ezreg/partials/refunds.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
<table ng-table="tableParams" show-filter="true" class="table table-bordered table-striped table-condensed">
<tr ng-repeat="row in $data track by row.id">
<td data-title="'Requested'" sortable="'requested'" style="width:170px"><label>{[row.requested | date:'short']}</label></td>
<td data-title="'Requester'" filter="{requester: 'text'}">{[row.requester]}</td>
<td data-title="'Event'" sortable="'registration__event__title'" filter="{registration__event__title__icontains: 'text'}"><a href="{[eventLink(row.event_id)]}">{[row.event]}</a></td>
<td data-title="'Registration'" filter="{registrant: 'text'}"><a href="{[registrationLink(row.registration)]}">{[row.registrant]}</a></td>
<td data-title="'Paid'">${[row.paid]}</td>
<td data-title="'Refund'" sortable="'amount'">${[row.amount]}</td>
<td data-title="'External ID'" filter="{registration__payment__external_id__icontains: 'text'}" sortable="'registration__payment__external_id'">{[row.external_id]}</td>
<td data-title="'Status'" sortable="'status'" filter="{status__icontains: 'text'}" style="width:170px"
ng-class="{completed:row.status=='completed',pending:row.status=='pending',cancelled:row.status=='cancelled'}">
<label>{[row.status]}</label>
</td>
<td data-title="'Updated by'" filter="{admin: 'text'}">{[row.admin]}</td>
<td data-title="'Updated'" sortable="'updated'">{[row.updated | date: 'short']}</td>
<td data-title="'Actions'">
<div class="btn-group" dropdown is-open="isopen[row.id]" ng-if="row.status=='pending'">
<button type="button" class="btn btn-default" dropdown-toggle ng-disabled="disabled">
Expand Down

0 comments on commit 8268b6e

Please sign in to comment.