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
...
 
@@ -2,12 +2,14 @@ from decimal import Decimal
 
from django.core.exceptions import ObjectDoesNotExist
 
from django.core.exceptions import ValidationError
 
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
 

	
 
from cart import CartController
 
from credit_note import CreditNoteController
...
 
@@ -146,12 +148,14 @@ class InvoiceController(ForId, object):
 
        commerce.LineItem.objects.bulk_create(line_items)
 

	
 
        invoice.value = invoice_value
 

	
 
        invoice.save()
 

	
 
        cls.email_on_invoice_creation(invoice)
 

	
 
        return invoice
 

	
 
    def can_view(self, user=None, access_code=None):
 
        ''' Returns true if the accessing user is allowed to view this invoice,
 
        or if the given access code matches this invoice's user's access code.
 
        '''
...
 
@@ -311,6 +315,36 @@ class InvoiceController(ForId, object):
 
        if amount == 0:
 
            self.void()
 
            return
 

	
 
        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)