@classmethod<EOL><INDENT>def _apply_credit_notes(cls, invoice):<DEDENT>
<EOL>invoices = commerce.Invoice.objects.filter(<EOL>user=invoice.user,<EOL>status=commerce.Invoice.STATUS_UNPAID,<EOL>)<EOL>if invoices.count() > <NUM_LIT:1>:<EOL><INDENT>return<EOL><DEDENT>notes = commerce.CreditNote.unclaimed().filter(<EOL>invoice__user=invoice.user<EOL>)<EOL>for note in notes:<EOL><INDENT>try:<EOL><INDENT>CreditNoteController(note).apply_to_invoice(invoice)<EOL><DEDENT>except ValidationError:<EOL><INDENT>break<EOL><DEDENT><DEDENT>invoice.refresh_from_db()<EOL>
Applies the user's credit notes to the given invoice on creation.