Adds form for generating a cancellation fee.
This commit is contained in:
parent
d4f4312178
commit
2ca644e500
2 changed files with 27 additions and 0 deletions
|
@ -3,6 +3,7 @@ from registrasion.models import commerce
|
||||||
from registrasion.models import inventory
|
from registrasion.models import inventory
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
class ApplyCreditNoteForm(forms.Form):
|
class ApplyCreditNoteForm(forms.Form):
|
||||||
|
@ -31,6 +32,14 @@ class ApplyCreditNoteForm(forms.Form):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class CancellationFeeForm(forms.Form):
|
||||||
|
|
||||||
|
percentage = forms.DecimalField(
|
||||||
|
required=True,
|
||||||
|
min_value=0,
|
||||||
|
max_value=100,
|
||||||
|
)
|
||||||
|
|
||||||
class ManualCreditNoteRefundForm(forms.ModelForm):
|
class ManualCreditNoteRefundForm(forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -765,6 +765,9 @@ def credit_note(request, note_id, access_code=None):
|
||||||
# to an invoice.
|
# to an invoice.
|
||||||
"refund_form": form, # A form for applying a *manual*
|
"refund_form": form, # A form for applying a *manual*
|
||||||
# refund of the credit note.
|
# refund of the credit note.
|
||||||
|
"cancellation_fee_form" : form, # A form for generating an
|
||||||
|
# invoice with a
|
||||||
|
# cancellation fee
|
||||||
}
|
}
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
@ -783,6 +786,11 @@ def credit_note(request, note_id, access_code=None):
|
||||||
prefix="refund_note"
|
prefix="refund_note"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cancellation_fee_form = forms.CancellationFeeForm(
|
||||||
|
request.POST or None,
|
||||||
|
prefix="cancellation_fee"
|
||||||
|
)
|
||||||
|
|
||||||
if request.POST and apply_form.is_valid():
|
if request.POST and apply_form.is_valid():
|
||||||
inv_id = apply_form.cleaned_data["invoice"]
|
inv_id = apply_form.cleaned_data["invoice"]
|
||||||
invoice = commerce.Invoice.objects.get(pk=inv_id)
|
invoice = commerce.Invoice.objects.get(pk=inv_id)
|
||||||
|
@ -805,10 +813,20 @@ def credit_note(request, note_id, access_code=None):
|
||||||
prefix="refund_note",
|
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 = {
|
data = {
|
||||||
"credit_note": current_note.credit_note,
|
"credit_note": current_note.credit_note,
|
||||||
"apply_form": apply_form,
|
"apply_form": apply_form,
|
||||||
"refund_form": refund_form,
|
"refund_form": refund_form,
|
||||||
|
"cancellation_fee_form": cancellation_fee_form,
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, "registrasion/credit_note.html", data)
|
return render(request, "registrasion/credit_note.html", data)
|
||||||
|
|
Loading…
Reference in a new issue