Adds available_credit tag, and adds a view for refunding an invoice to generate a credit note.
This commit is contained in:
		
							parent
							
								
									6b10a0a7e4
								
							
						
					
					
						commit
						2c94e7538a
					
				
					 3 changed files with 33 additions and 0 deletions
				
			
		| 
						 | 
					@ -16,6 +16,16 @@ def available_categories(context):
 | 
				
			||||||
    return CategoryController.available_categories(context.request.user)
 | 
					    return CategoryController.available_categories(context.request.user)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@register.assignment_tag(takes_context=True)
 | 
				
			||||||
 | 
					def available_credit(context):
 | 
				
			||||||
 | 
					    ''' Returns the amount of unclaimed credit available for this user. '''
 | 
				
			||||||
 | 
					    notes = rego.CreditNote.unclaimed().filter(
 | 
				
			||||||
 | 
					        invoice__user=context.request.user,
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    ret = notes.values("amount").aggregate(Sum("amount"))["amount__sum"] or 0
 | 
				
			||||||
 | 
					    return 0 - ret
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@register.assignment_tag(takes_context=True)
 | 
					@register.assignment_tag(takes_context=True)
 | 
				
			||||||
def invoices(context):
 | 
					def invoices(context):
 | 
				
			||||||
    ''' Returns all of the invoices that this user has. '''
 | 
					    ''' Returns all of the invoices that this user has. '''
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,6 +10,8 @@ urlpatterns = patterns(
 | 
				
			||||||
    url(r"^invoice/([0-9]+)/([A-Z0-9]+)$", views.invoice, name="invoice"),
 | 
					    url(r"^invoice/([0-9]+)/([A-Z0-9]+)$", views.invoice, name="invoice"),
 | 
				
			||||||
    url(r"^invoice/([0-9]+)/manual_payment$",
 | 
					    url(r"^invoice/([0-9]+)/manual_payment$",
 | 
				
			||||||
        views.manual_payment, name="manual_payment"),
 | 
					        views.manual_payment, name="manual_payment"),
 | 
				
			||||||
 | 
					    url(r"^invoice/([0-9]+)/refund$",
 | 
				
			||||||
 | 
					        views.refund, name="refund"),
 | 
				
			||||||
    url(r"^invoice_access/([A-Z0-9]+)$", views.invoice_access,
 | 
					    url(r"^invoice_access/([A-Z0-9]+)$", views.invoice_access,
 | 
				
			||||||
        name="invoice_access"),
 | 
					        name="invoice_access"),
 | 
				
			||||||
    url(r"^profile$", "edit_profile", name="attendee_edit"),
 | 
					    url(r"^profile$", "edit_profile", name="attendee_edit"),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -524,3 +524,24 @@ def manual_payment(request, invoice_id):
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return render(request, "registrasion/manual_payment.html", data)
 | 
					    return render(request, "registrasion/manual_payment.html", data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@login_required
 | 
				
			||||||
 | 
					def refund(request, invoice_id):
 | 
				
			||||||
 | 
					    ''' Allows staff to refund payments against an invoice and request a
 | 
				
			||||||
 | 
					    credit note.'''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if not request.user.is_staff:
 | 
				
			||||||
 | 
					        raise Http404()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    invoice_id = int(invoice_id)
 | 
				
			||||||
 | 
					    inv = get_object_or_404(rego.Invoice, pk=invoice_id)
 | 
				
			||||||
 | 
					    current_invoice = InvoiceController(inv)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        current_invoice.refund()
 | 
				
			||||||
 | 
					        messages.success(request, "This invoice has been refunded.")
 | 
				
			||||||
 | 
					    except ValidationError as ve:
 | 
				
			||||||
 | 
					        messages.error(request, ve)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return redirect("invoice", invoice_id)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue