code: def account_balance_before(self):
          
          # TODO: Consider moving to annotation, particularly once we can count on Django 1.11's subquery support
          transaction_date = self.transaction.date
          return self.account.balance(
              leg_query=(
                  models.Q(transaction__date__lt=transaction_date)
                  | (
                      models.Q(transaction__date=transaction_date)
                      & models.Q(transaction_id__lt=self.transaction_id)
                  )
              )
          )
docs: Get the balance of the account associated with this leg before the transaction