@staticmethod
    def _rebuild_ledger_value_from_transactions(ledger_value, transactions):
        balance = 0
        for transaction in transactions:
            updated_values = _compute_ledger_values(balance, transaction)
            new_balance = updated_values.balance
            new_delta = updated_values.balance - balance
            if new_balance != transaction.updated_balance or new_delta != transaction.delta:
                transaction.delta = new_delta
                transaction.updated_balance = new_balance
                ledger_value.track_update(transaction)
            elif not transaction.is_saved():
                ledger_value.track_create(transaction)
            balance = new_balance
        if balance != ledger_value.balance or ledger_value.has_tracked_models():
            ledger_value.balance = balance

        return ledger_value
dataset/ETHPy150Open dimagi/commcare-hq/corehq/form_processor/backends/sql/ledger.py/LedgerProcessorSQL._rebuild_ledger_value_from_transactions/original