Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
amschaal committed Jan 15, 2020
1 parent 2ede15d commit fee06be
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ezreg/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def __init__(self, *args, **kwargs):
self.fields['status'].help_text = 'A status of PAID may not be changed. Refunds may be issued, but the original status must remain.'
class Meta:
model=Payment
fields = ('status','refunded','admin_notes')
fields = ('status','admin_notes') # ,'refunded'
def clean_refunded(self):
refunded = self.cleaned_data['refunded']
if refunded and not self.instance.amount or refunded > self.instance.amount:
Expand Down
3 changes: 3 additions & 0 deletions ezreg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ def set_status(self, status, user):
@property
def can_cancel(self):
return self.status == Refund.STATUS_PENDING
@property
def can_complete(self):
return self.status == Refund.STATUS_PENDING and self.amount <= self.registration.payment.amount_remaining

class PaymentProcessor(models.Model):
processor_id = models.CharField(max_length=30)
Expand Down
5 changes: 4 additions & 1 deletion ezreg/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,14 @@
{%if user.is_authenticated%}
<li><a href="{% url 'manage_events' %}">Events</a></li>
<li><a href="{% url 'registration_search' %}">Registrations</a></li>
{% if OrganizerUserPermission.PERMISSION_MANAGE_PROCESSORS in all_user_permissions %}
{% if request.user.is_staff %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Admin <b class="caret"></b></a>
<ul class="dropdown-menu">
{% if OrganizerUserPermission.PERMISSION_MANAGE_PROCESSORS in all_user_permissions %}
<li><a href="{% url 'payment_processors' %}">Manage Payment Processors</a></li>
{% endif %}
<li><a href="{% url 'pending_refunds' %}">Pending Refunds</a></li>
</ul>
</li>
{% endif %}
Expand Down
21 changes: 13 additions & 8 deletions ezreg/templates/ezreg/partials/payment.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ <h2>Payment{% if permissions and 'admin' in permissions%} <a href="{% url 'modif
{% if registration.payment.refunded and permissions and 'admin' in permissions %}<tr><th>Refunded</th><td>${{registration.payment.refunded}}</td></tr>{% endif %}
{% if registration.payment.admin_notes and permissions and 'admin' in permissions %}<tr><th>Admin Notes</th><td>{{registration.payment.admin_notes}}</td></tr>{% endif %}
</table>
{% if registration.refunds.all|length > 0 and permissions and 'admin' in permissions%}
<h2>Refunds</h2>
<table class="table table-bordered table-striped table-condensed">
<tr><th>Requested</th><th>Requester</th><th>Amount</th><th>Status</th><td></td></tr>
{% for r in registration.refunds.all %}
<tr><td>{{r.requested}}</td><td>{{r.requester}}</td><td>${{r.amount}}</td><td>{{r.status}}</td><td><a class="btn" href="{% url 'complete_refund' id=r.id %}">Complete</a></td></tr>
{% endfor %}
</table>
{% if permissions and 'admin' in permissions%}
<h2>Refunds</h2>
{% if registration.refunds.all|length > 0%}
<table class="table table-bordered table-striped table-condensed">
<tr><th>Requested</th><th>Requester</th><th>Amount</th><th>Status</th><td></td></tr>
{% for r in registration.refunds.all %}
<tr><td>{{r.requested}}</td><td>{{r.requester}}</td><td>${{r.amount}}</td><td>{{r.status}}</td><td>{% if r.can_cancel %}<a class="btn btn-danger" href="{% url 'cancel_refund' id=r.id %}">Cancel</a>{% endif %}</td></tr>
{% endfor %}
</table>
{% else %}
<p>There are no requested refunds at this time.</p>
{% endif %}
<p><a href="{% url 'request_refund' id=registration.id%}">Request</a> a refund.</p>
{% endif %}
{% endif %}
2 changes: 2 additions & 0 deletions ezreg/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@
url(r'^registrations/(?P<id>[A-Za-z0-9_\-]{10})/update_status/$', views.update_registration_status, name="update_registration_status"),
url(r'^registrations/(?P<id>[A-Za-z0-9_\-]{10})/request_refund/$', views.request_refund, name="request_refund"),
url(r'^registrations/(?P<id>[A-Za-z0-9_\-]{10})/pay/$', views.pay, name="pay"),
url(r'^refunds/pending/$', views.pending_refunds, name='pending_refunds'),
url(r'^refunds/(?P<id>[a-f0-9\-]+)/complete/$', views.complete_refund, name="complete_refund"),
url(r'^refunds/(?P<id>[a-f0-9\-]+)/cancel/$', views.complete_refund, name="cancel_refund"),
url(r'^payment_processors/$', views.payment_processors, name='payment_processors'),
url(r'^payment_processors/create/$', views.create_payment_processor, name='create_payment_processor'),
url(r'^payment_processors/(?P<id>\d+)/modify/$', views.modify_payment_processor, name='modify_payment_processor'),
Expand Down
9 changes: 7 additions & 2 deletions ezreg/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,22 @@ def request_refund(request, id):
return redirect('registration',id=registration.id) #event.get_absolute_url()
return render(request, 'ezreg/request_refund.html', {'form':form,'registration':registration} )

@user_passes_test(lambda u: u.is_staff)
def pending_refunds(request):
refunds = Refund.objects.filter(status=Refund.STATUS_PENDING)
return render(request, 'ezreg/admin/pending_refunds.html', {'refunds':refunds})

@user_passes_test(lambda u: u.is_staff)
def complete_refund(request, id):
refund = Refund.objects.get(id=id)
refund.set_status(Refund.STATUS_COMPLETED,request.user)
permissions = refund.registration.event.get_user_permissions(request.user) if request.user.is_authenticated else []
return render(request, 'ezreg/registration.html', {'registration':refund.registration, 'permissions': permissions, 'message': "Refund request has been completed. Use your browser's back button to return."}
return render(request, 'ezreg/registration.html', {'registration':refund.registration, 'permissions': permissions, 'message': "Refund request has been completed. Use your browser's back button to return."})

@generic_permission_decorator([OrganizerUserPermission.PERMISSION_ADMIN],'organizer__events__registrations__payment__refunds__id','id')
def cancel_refund(request, id):
refund = Refund.objects.get(id=id)
refund.set_status(Refund.STATUS_COMPLETED,request.user)
refund.set_status(Refund.STATUS_CANCELLED,request.user)
permissions = refund.registration.event.get_user_permissions(request.user) if request.user.is_authenticated else []
return render(request, 'ezreg/registration.html', {'registration':refund.registration, 'permissions': permissions, 'message': "Refund request has been cancelled. Use your browser's back button to return."})

Expand Down

0 comments on commit fee06be

Please sign in to comment.