Credit note is automatically applied if you have a single invoice
This commit is contained in:
parent
05c5cfcb4e
commit
82254a7bf5
1 changed files with 20 additions and 0 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue