Changeset - 12e04c248fb1
[Not reviewed]
0 3 0
Christopher Neugebauer - 8 years ago 2016-04-24 22:26:54
chrisjrn@gmail.com
Credit notes are now generated when invoices are overpaid, or invoices are paid into void or refunded invoices. Closes #37.
3 files changed with 64 insertions and 18 deletions:
0 comments (0 inline, 0 general)
registrasion/controllers/invoice.py
Show inline comments
...
 
@@ -15,2 +15,3 @@ from for_id import ForId
 

	
 

	
 
class InvoiceController(ForId, object):
...
 
@@ -197,7 +198,2 @@ class InvoiceController(ForId, object):
 

	
 
                if remainder < 0:
 
                    CreditNoteController.generate_from_invoice(
 
                        self.invoice,
 
                        0 - remainder,
 
                    )
 
            elif total_paid == 0 and num_payments > 0:
...
 
@@ -217,2 +213,13 @@ class InvoiceController(ForId, object):
 

	
 
        # Generate credit notes from residual payments
 
        residual = 0
 
        if self.invoice.is_paid:
 
            if remainder < 0:
 
                residual = 0 - remainder
 
        elif self.invoice.is_void or self.invoice.is_refunded:
 
            residual = total_paid
 

	
 
        if residual != 0:
 
            CreditNoteController.generate_from_invoice(self.invoice, residual)
 

	
 
    def _mark_paid(self):
registrasion/tests/controller_helpers.py
Show inline comments
...
 
@@ -36,3 +36,3 @@ class TestingInvoiceController(InvoiceController):
 

	
 
    def pay(self, reference, amount):
 
    def pay(self, reference, amount, pre_validate=True):
 
        ''' Testing method for simulating an invoice paymenht by the given
...
 
@@ -40,3 +40,6 @@ class TestingInvoiceController(InvoiceController):
 

	
 
        self.validate_allowed_to_pay()
 
        if pre_validate:
 
            # Manual payments don't pre-validate; we should test that things
 
            # still work if we do silly things.
 
            self.validate_allowed_to_pay()
 

	
registrasion/tests/test_invoice.py
Show inline comments
...
 
@@ -26,2 +26,6 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
    def _credit_note_for_invoice(self, invoice):
 
        note = commerce.CreditNote.objects.get(invoice=invoice)
 
        return TestingCreditNoteController(note)
 

	
 
    def test_create_invoice(self):
...
 
@@ -316,4 +320,3 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
        # There should be one credit note generated out of the invoice.
 
        credit_note = commerce.CreditNote.objects.get(invoice=invoice.invoice)
 
        cn = TestingCreditNoteController(credit_note)
 
        cn = self._credit_note_for_invoice(invoice.invoice)
 

	
...
 
@@ -344,4 +347,3 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
        # There should be one credit note generated out of the invoice.
 
        credit_note = commerce.CreditNote.objects.get(invoice=invoice.invoice)
 
        cn = TestingCreditNoteController(credit_note)
 
        cn = self._credit_note_for_invoice(invoice.invoice)
 

	
...
 
@@ -383,4 +385,3 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
        # There should be one credit note generated out of the invoice.
 
        credit_note = commerce.CreditNote.objects.get(invoice=invoice.invoice)
 
        cn = TestingCreditNoteController(credit_note)
 
        cn = self._credit_note_for_invoice(invoice.invoice)
 

	
...
 
@@ -417,5 +418,4 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
        credit_note = commerce.CreditNote.objects.get(invoice=invoice.invoice)
 
        cn = self._credit_note_for_invoice(invoice.invoice)
 

	
 
        cn = TestingCreditNoteController(credit_note)
 
        cn.refund()
...
 
@@ -446,5 +446,3 @@ class InvoiceTestCase(RegistrationCartTestCase):
 

	
 
        credit_note = commerce.CreditNote.objects.get(invoice=invoice.invoice)
 

	
 
        cn = TestingCreditNoteController(credit_note)
 
        cn = self._credit_note_for_invoice(invoice.invoice)
 

	
...
 
@@ -462 +460,39 @@ class InvoiceTestCase(RegistrationCartTestCase):
 
            cn.refund()
 

	
 
    def test_money_into_void_invoice_generates_credit_note(self):
 
        invoice = self._invoice_containing_prod_1(1)
 
        invoice.void()
 

	
 
        val = invoice.invoice.value
 

	
 
        invoice.pay("Paying into the void.", val, pre_validate=False)
 
        cn = self._credit_note_for_invoice(invoice.invoice)
 
        self.assertEqual(val, cn.credit_note.value)
 

	
 
    def test_money_into_refunded_invoice_generates_credit_note(self):
 
        invoice = self._invoice_containing_prod_1(1)
 

	
 
        val = invoice.invoice.value
 

	
 
        invoice.pay("Paying the first time.", val)
 
        invoice.refund()
 

	
 
        cnval = val - 1
 
        invoice.pay("Paying into the void.", cnval, pre_validate=False)
 

	
 
        notes = commerce.CreditNote.objects.filter(invoice=invoice.invoice)
 
        notes = sorted(notes, key = lambda note: note.value)
 
        
 
        self.assertEqual(cnval, notes[0].value)
 
        self.assertEqual(val, notes[1].value)
 

	
 
    def test_money_into_paid_invoice_generates_credit_note(self):
 
        invoice = self._invoice_containing_prod_1(1)
 

	
 
        val = invoice.invoice.value
 

	
 
        invoice.pay("Paying the first time.", val)
 

	
 
        invoice.pay("Paying into the void.", val, pre_validate=False)
 
        cn = self._credit_note_for_invoice(invoice.invoice)
 
        self.assertEqual(val, cn.credit_note.value)
0 comments (0 inline, 0 general)