Changeset - 82254a7bf513
[Not reviewed]
0 1 0
Christopher Neugebauer - 8 years ago 2016-09-15 00:22:12
chrisjrn@gmail.com
Credit note is automatically applied if you have a single invoice
1 file changed with 20 insertions and 0 deletions:
0 comments (0 inline, 0 general)
registrasion/controllers/invoice.py
Show inline comments
...
 
@@ -198,10 +198,30 @@ class InvoiceController(ForId, object):
 

	
 
        commerce.LineItem.objects.bulk_create(line_items)
 

	
 
        cls._apply_credit_notes(invoice)
 
        cls.email_on_invoice_creation(invoice)
 

	
 
        return invoice
 

	
 
    @classmethod
 
    def _apply_credit_notes(cls, invoice):
 
        ''' Applies the user's credit notes to the given invoice on creation.
 
        '''
 

	
 
        notes = commerce.CreditNote.objects.filter(invoice__user=invoice.user)
 

	
 
        if len(notes) == 0:
 
            return
 

	
 
        for note in notes:
 
            try:
 
                CreditNoteController(note).apply_to_invoice(invoice)
 
            except ValidationError:
 
                # ValidationError will get raised once we're overpaying.
 
                break
 

	
 
        invoice.refresh_from_db()
 

	
 
    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.
0 comments (0 inline, 0 general)