Skip to content

Commit

Permalink
Fix currency when importing to foreign accounts (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubkottnauer authored May 20, 2024
1 parent 5fa34b4 commit 34811d8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/models/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def generate_transactions
name: row["name"] || "Imported transaction",
date: Date.iso8601(row["date"]),
category: category,
amount: BigDecimal(row["amount"]) * -1 # User inputs amounts with opposite signage of our internal representation
amount: BigDecimal(row["amount"]) * -1, # User inputs amounts with opposite signage of our internal representation
currency: account.currency

transactions << txn
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/imports/transactions/_transaction.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
</div>

<div class="ml-auto">
<%= content_tag :p, format_money(-transaction.amount), class: ["whitespace-nowrap", BigDecimal(transaction.amount).negative? ? "text-green-600" : "text-red-600"] %>
<%= content_tag :p, format_money(Money.new(-transaction.amount, @import.account.currency)), class: ["whitespace-nowrap", BigDecimal(transaction.amount).negative? ? "text-green-600" : "text-red-600"] %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/imports/transactions/_transaction_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="bg-gray-25 rounded-xl p-1 w-full">
<div class="py-2 px-4 flex items-center justify-between font-medium text-xs text-gray-500">
<h4><%= date.strftime("%b %d, %Y") %> &middot; <%= transactions.size %></h4>
<span><%= format_money -transactions.sum { |t| t.amount } %></span>
<span><%= format_money Money.new(-transactions.sum { |t| t.amount }, @import.account.currency) %></span>
</div>
<div class="bg-white shadow-xs rounded-md border border-alpha-black-25 divide-y divide-alpha-black-50">
<%= render partial: "imports/transactions/transaction", collection: transactions %>
Expand Down

0 comments on commit 34811d8

Please sign in to comment.