(self)
This goes through all credit lines that:
        - do not have feature/product rates, but specify the related subscription and billing account
        - do not have feature/product rates or a subscription, but specify the related billing account
This goes through all credit lines that:
        - do not have feature/product rates, but specify the related subscription and billing account
        - do not have feature/product rates or a subscription, but specify the related billing account
This goes through all credit lines that : - do not have feature / product rates but specify the related subscription and billing account - do not have feature / product rates or a subscription but specify the related billing account
def calculate_credit_adjustments(self):
        """
        This goes through all credit lines that:
        - do not have feature/product rates, but specify the related subscription and billing account
        - do not have feature/product rates or a subscription, but specify the related billing account
        """
        # first apply credits to all the line items
        for line_item in self.lineitem_set.all():
            line_item.calculate_credit_adjustments()

        # finally, apply credits to the leftover invoice balance
        current_total = self.get_total()
        credit_lines = CreditLine.get_credits_for_invoice(self)
        CreditLine.apply_credits_toward_balance(credit_lines, current_total, invoice=self)
def calculate_credit_adjustments ( self ) : # first apply credits to all the line items for line_item in self . lineitem_set . all ( ) : line_item . calculate_credit_adjustments ( ) # finally, apply credits to the leftover invoice balance current_total = self . get_total ( ) credit_lines = CreditLine . get_credits_for_invoice ( self ) CreditLine . apply_credits_toward_balance ( credit_lines , current_total , invoice = self )