diff --git a/lib/gnucash/transaction.rb b/lib/gnucash/transaction.rb index 84f110f..a472acf 100644 --- a/lib/gnucash/transaction.rb +++ b/lib/gnucash/transaction.rb @@ -14,16 +14,18 @@ module Gnucash unless value_parts.size == 2 and value_parts[1] == '100' raise "Unexpected value format: #{value_str.inspect}" end + account_id = split_node.xpath('split:account').text + value = value_parts.first.to_i + account = @book.find_account_by_id(account_id) + unless account + raise "Could not find account with ID #{account_id} for transaction #{@id}" + end + account.add_transaction(self, value) { - account_id: split_node.xpath('split:account').text, - value: value_parts.first.to_i, + account_id: account_id, + value: value, } end - @splits.each do |split| - account = @book.find_account_by_id(split[:account_id]) - raise "Could not find account with ID #{split[:account_id]} for transaction #{@id}" unless account - account.add_transaction(self, split[:value]) - end end end end