Changeset - e946af0f0487
[Not reviewed]
0 1 0
Christopher Neugebauer - 8 years ago 2016-08-21 06:56:05
chrisjrn@gmail.com
Adds functions for mailing invoices when certain events occur.
1 file changed with 34 insertions and 0 deletions:
0 comments (0 inline, 0 general)
registrasion/controllers/invoice.py
Show inline comments
...
 
@@ -5,6 +5,8 @@ from django.db import transaction
 
from django.db.models import Sum
 
from django.utils import timezone
 

	
 
from registrasion.contrib.mail import send_email
 

	
 
from registrasion.models import commerce
 
from registrasion.models import conditions
 
from registrasion.models import people
...
 
@@ -149,6 +151,8 @@ class InvoiceController(ForId, object):
 

	
 
        invoice.save()
 

	
 
        cls.email_on_invoice_creation(invoice)
 

	
 
        return invoice
 

	
 
    def can_view(self, user=None, access_code=None):
...
 
@@ -314,3 +318,33 @@ class InvoiceController(ForId, object):
 

	
 
        CreditNoteController.generate_from_invoice(self.invoice, amount)
 
        self.update_status()
 

	
 
    @classmethod
 
    def email(cls, invoice, kind):
 
        ''' Sends out an e-mail notifying the user about something to do
 
        with that invoice. '''
 

	
 
        context = {
 
            "invoice": invoice,
 
        }
 

	
 
        send_email(invoice.user.email, kind, context=context)
 

	
 
    @classmethod
 
    def email_on_invoice_creation(cls, invoice):
 
        ''' Sends out an e-mail notifying the user that an invoice has been
 
        created. '''
 

	
 
        cls.email(invoice, "invoice_created")
 

	
 
    @classmethod
 
    def email_on_invoice_change(cls, invoice, old_status, new_status):
 
        ''' Sends out all of the necessary notifications that the status of the
 
        invoice has changed to:
 

	
 
        - Invoice is now paid
 
        - Invoice is now refunded
 

	
 
        '''
 

	
 
        cls.email(invoice, "invoice_updated")
0 comments (0 inline, 0 general)