Changeset - 2ca644e5002d
[Not reviewed]
0 2 0
Christopher Neugebauer - 8 years ago 2016-09-15 02:25:34
chrisjrn@gmail.com
Adds form for generating a cancellation fee.
2 files changed with 27 insertions and 0 deletions:
0 comments (0 inline, 0 general)
registrasion/forms.py
Show inline comments
 
from registrasion.controllers.product import ProductController
 
from registrasion.models import commerce
 
from registrasion.models import inventory
 

	
 
from django import forms
 
from django.core.exceptions import ValidationError
 

	
 

	
 
class ApplyCreditNoteForm(forms.Form):
 

	
 
    def __init__(self, user, *a, **k):
 
        ''' User: The user whose invoices should be made available as
...
 
@@ -28,12 +29,20 @@ class ApplyCreditNoteForm(forms.Form):
 

	
 
    invoice = forms.ChoiceField(
 
        required=True,
 
    )
 

	
 

	
 
class CancellationFeeForm(forms.Form):
 

	
 
    percentage = forms.DecimalField(
 
        required=True,
 
        min_value=0,
 
        max_value=100,
 
    )
 

	
 
class ManualCreditNoteRefundForm(forms.ModelForm):
 

	
 
    class Meta:
 
        model = commerce.ManualCreditNoteRefund
 
        fields = ["reference"]
 

	
registrasion/views.py
Show inline comments
...
 
@@ -762,12 +762,15 @@ def credit_note(request, note_id, access_code=None):
 
                {
 
                    "credit_note": models.commerce.CreditNote(),
 
                    "apply_form": form,  # A form for applying credit note
 
                                         # to an invoice.
 
                    "refund_form": form, # A form for applying a *manual*
 
                                         # refund of the credit note.
 
                    "cancellation_fee_form" : form, # A form for generating an
 
                                                    # invoice with a
 
                                                    # cancellation fee
 
                }
 

	
 
    '''
 

	
 
    note_id = int(note_id)
 
    current_note = CreditNoteController.for_id_or_404(note_id)
...
 
@@ -780,12 +783,17 @@ def credit_note(request, note_id, access_code=None):
 

	
 
    refund_form = forms.ManualCreditNoteRefundForm(
 
        request.POST or None,
 
        prefix="refund_note"
 
    )
 

	
 
    cancellation_fee_form = forms.CancellationFeeForm(
 
        request.POST or None,
 
        prefix="cancellation_fee"
 
    )
 

	
 
    if request.POST and apply_form.is_valid():
 
        inv_id = apply_form.cleaned_data["invoice"]
 
        invoice = commerce.Invoice.objects.get(pk=inv_id)
 
        current_note.apply_to_invoice(invoice)
 
        messages.success(
 
            request,
...
 
@@ -802,16 +810,26 @@ def credit_note(request, note_id, access_code=None):
 
            "Applied manual refund to credit note."
 
        )
 
        refund_form = forms.ManualCreditNoteRefundForm(
 
            prefix="refund_note",
 
        )
 

	
 
    elif request.POST and cancellation_fee_form.is_valid():
 
        percentage = cancellation_fee_form.cleaned_data["percentage"]
 
        invoice = current_note.cancellation_fee(percentage)
 
        messages.success(
 
            request,
 
            "Generated cancellation fee for credit note %d." % note_id,
 
        )
 
        return redirect("invoice", invoice.invoice.id)
 

	
 
    data = {
 
        "credit_note": current_note.credit_note,
 
        "apply_form": apply_form,
 
        "refund_form": refund_form,
 
        "cancellation_fee_form": cancellation_fee_form,
 
    }
 

	
 
    return render(request, "registrasion/credit_note.html", data)
 

	
 

	
 
@user_passes_test(_staff_only)
0 comments (0 inline, 0 general)