diff --git a/registrasion/controllers/invoice.py b/registrasion/controllers/invoice.py index 03be199a..1b70640e 100644 --- a/registrasion/controllers/invoice.py +++ b/registrasion/controllers/invoice.py @@ -245,6 +245,12 @@ class InvoiceController(ForId, object): if residual != 0: CreditNoteController.generate_from_invoice(self.invoice, residual) + self.email_on_invoice_change( + self.invoice, + old_status, + self.invoice.status, + ) + def _mark_paid(self): ''' Marks the invoice as paid, and updates the attached cart if necessary. ''' @@ -347,4 +353,15 @@ class InvoiceController(ForId, object): ''' + # The statuses that we don't care about. + silent_status = [ + commerce.Invoice.STATUS_VOID, + commerce.Invoice.STATUS_UNPAID, + ] + + if old_status == new_status: + return + if False and new_status in silent_status: + pass + cls.email(invoice, "invoice_updated") diff --git a/registrasion/tests/test_invoice.py b/registrasion/tests/test_invoice.py index 32ec6c2e..98d479b6 100644 --- a/registrasion/tests/test_invoice.py +++ b/registrasion/tests/test_invoice.py @@ -536,8 +536,37 @@ class InvoiceTestCase(RegistrationCartTestCase): def test_sends_email_on_invoice_creation(self): invoice = self._invoice_containing_prod_1(1) - assert(1, len(self.emails)) + self.assertEquals(1, len(self.emails)) email = self.emails[0] self.assertEquals(self.USER_1.email, email["to"]) self.assertEquals("invoice_created", email["kind"]) self.assertEquals(invoice.invoice, email["context"]["invoice"]) + + def test_sends_first_change_email_on_invoice_fully_paid(self): + invoice = self._invoice_containing_prod_1(1) + + self.assertEquals(1, len(self.emails)) + invoice.pay("Partial", invoice.invoice.value - 1) + # Should have an "invoice_created" email and nothing else. + self.assertEquals(1, len(self.emails)) + invoice.pay("Remainder", 1) + self.assertEquals(2, len(self.emails)) + + email = self.emails[1] + self.assertEquals(self.USER_1.email, email["to"]) + self.assertEquals("invoice_updated", email["kind"]) + self.assertEquals(invoice.invoice, email["context"]["invoice"]) + + def test_sends_email_when_invoice_refunded(self): + invoice = self._invoice_containing_prod_1(1) + + self.assertEquals(1, len(self.emails)) + invoice.pay("Payment", invoice.invoice.value) + self.assertEquals(2, len(self.emails)) + invoice.refund() + self.assertEquals(3, len(self.emails)) + + email = self.emails[2] + self.assertEquals(self.USER_1.email, email["to"]) + self.assertEquals("invoice_updated", email["kind"]) + self.assertEquals(invoice.invoice, email["context"]["invoice"])