Changeset - d4f4312178cd
[Not reviewed]
0 2 0
Christopher Neugebauer - 8 years ago 2016-09-15 02:15:40
chrisjrn@gmail.com
Adds cancellation fee implementation and tests
2 files changed with 51 insertions and 0 deletions:
0 comments (0 inline, 0 general)
registrasion/controllers/credit_note.py
Show inline comments
 
import datetime
 

	
 
from django.db import transaction
 

	
 
from registrasion.models import commerce
...
 
@@ -53,3 +55,27 @@ class CreditNoteController(ForId, object):
 
        inv.update_status()
 

	
 
    # TODO: Add administration fee generator.
 
    @transaction.atomic
 
    def cancellation_fee(self, percentage):
 
        ''' Generates an invoice with a cancellation fee, and applies
 
        credit to the invoice.
 

	
 
        percentage (Decimal): The percentage of the credit note to turn into
 
        a cancellation fee. Must be 0 <= percentage <= 100.
 
        '''
 

	
 
        from invoice import InvoiceController  # Circular imports bleh.
 

	
 
        assert(percentage >= 0 and percentage <= 100)
 

	
 
        cancellation_fee = self.credit_note.value * percentage / 100
 
        due = datetime.timedelta(days=1)
 
        item = [("Cancellation fee", cancellation_fee)]
 
        invoice = InvoiceController.manual_invoice(
 
            self.credit_note.invoice.user, due, item
 
        )
 

	
 
        if not invoice.is_paid:
 
            self.apply_to_invoice(invoice)
 

	
 
        return InvoiceController(invoice)
registrasion/tests/test_credit_note.py
Show inline comments
...
 
@@ -440,3 +440,28 @@ class CreditNoteTestCase(TestHelperMixin, RegistrationCartTestCase):
 
            # Generate invoice that should be automatically paid
 
            invoice2 = self._manual_invoice(1)
 
            self.assertTrue(invoice2.invoice.is_paid)
 

	
 
    def test_cancellation_fee_is_applied(self):
 

	
 
        invoice1 = self._manual_invoice(1)
 
        invoice1.pay("Pay", invoice1.invoice.value)
 
        invoice1.refund()
 

	
 
        percentage = 15
 

	
 
        cn = self._credit_note_for_invoice(invoice1.invoice)
 
        canc = cn.cancellation_fee(15)
 

	
 
        # Cancellation fee exceeds the amount for the invoice.
 
        self.assertTrue(canc.invoice.is_paid)
 

	
 
        # Cancellation fee is equal to 15% of credit note's value
 
        self.assertEqual(
 
            canc.invoice.value,
 
            cn.credit_note.value * percentage / 100
 
        )
 

	
 
    def test_cancellation_fee_is_applied_when_another_invoice_is_unpaid(self):
 

	
 
        extra_invoice = self._manual_invoice(23)
 
        self.test_cancellation_fee_is_applied()
0 comments (0 inline, 0 general)