Invoices now send e-mails when created, paid, or refunded.
This commit is contained in:
parent
924906d38c
commit
7bf372f92a
2 changed files with 47 additions and 1 deletions
|
@ -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")
|
||||
|
|
|
@ -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"])
|
||||
|
|
Loading…
Reference in a new issue