The personal finance app for everyone
Support multi-currency transfers (#1175)
Zach Gollwitzer949d3d80fa95
diff --git a/app/controllers/account/transfers_controller.rb b/app/controllers/account/transfers_controller.rbindex 4fbf4268..c8fd4877 100644--- a/app/controllers/account/transfers_controller.rb+++ b/app/controllers/account/transfers_controller.rb@@ -40,6 +40,6 @@ class Account::TransfersController < ApplicationControllerenddef transfer_params- params.require(:account_transfer).permit(:from_account_id, :to_account_id, :amount, :currency, :date, :name)+ params.require(:account_transfer).permit(:from_account_id, :to_account_id, :amount, :date, :name)endenddiff --git a/app/models/account/entry.rb b/app/models/account/entry.rbindex 345fe26b..56754cb6 100644--- a/app/models/account/entry.rb+++ b/app/models/account/entry.rb@@ -204,7 +204,6 @@ class Account::Entry < ApplicationRecordcurrent_qty = account.holding_qty(account_trade.security)if current_qty < account_trade.qty.abs- # i18n-tasks-use t('activerecord.errors.models.account/entry.attributes.base.invalid_sell_quantity')errors.add(:base,:invalid_sell_quantity,diff --git a/app/models/account/transfer.rb b/app/models/account/transfer.rbindex 402c3776..370d53a2 100644--- a/app/models/account/transfer.rb+++ b/app/models/account/transfer.rb@@ -46,7 +46,7 @@ class Account::Transfer < ApplicationRecorddef build_from_accounts(from_account, to_account, date:, amount:, currency:, name:)outflow = from_account.entries.build \amount: amount.abs,- currency: currency,+ currency: from_account.currency,date: date,name: name,marked_as_transfer: true,@@ -54,7 +54,7 @@ class Account::Transfer < ApplicationRecordinflow = to_account.entries.build \amount: amount.abs * -1,- currency: currency,+ currency: from_account.currency,date: date,name: name,marked_as_transfer: true,@@ -72,27 +72,23 @@ class Account::Transfer < ApplicationRecorddef transaction_countunless entries.size == 2- # i18n-tasks-use t('activerecord.errors.models.account/transfer.attributes.entries.must_have_exactly_2_entries')errors.add :entries, :must_have_exactly_2_entriesendenddef from_different_accountsaccounts = entries.map { |e| e.account_id }.uniq- # i18n-tasks-use t('activerecord.errors.models.account/transfer.attributes.entries.must_be_from_different_accounts')errors.add :entries, :must_be_from_different_accounts if accounts.size < entries.sizeenddef net_zero_flowsunless entries.sum(&:amount).zero?- # i18n-tasks-use t('activerecord.errors.models.account/transfer.attributes.entries.must_have_an_inflow_and_outflow_that_net_to_zero')errors.add :entries, :must_have_an_inflow_and_outflow_that_net_to_zeroendenddef all_transactions_markedunless entries.all?(&:marked_as_transfer)- # i18n-tasks-use t('activerecord.errors.models.account/transfer.attributes.entries.must_be_marked_as_transfer')errors.add :entries, :must_be_marked_as_transferendenddiff --git a/app/models/import.rb b/app/models/import.rbindex 590e94f4..2cb1e634 100644--- a/app/models/import.rb+++ b/app/models/import.rb@@ -179,7 +179,6 @@ class Import < ApplicationRecordbeginCSV.parse(raw_file_str || "", col_sep:)rescue CSV::MalformedCSVError- # i18n-tasks-use t('activerecord.errors.models.import.attributes.raw_file_str.invalid_csv_format')errors.add(:raw_file_str, :invalid_csv_format)endenddiff --git a/app/models/time_series/trend.rb b/app/models/time_series/trend.rbindex e4959bc9..b93db2bd 100644--- a/app/models/time_series/trend.rb+++ b/app/models/time_series/trend.rb@@ -83,21 +83,17 @@ class TimeSeries::Trenddef values_must_be_of_same_typeunless current.class == previous.class || [ previous, current ].any?(&:nil?)- # i18n-tasks-use t('activemodel.errors.models.time_series/trend.attributes.current.must_be_of_the_same_type_as_previous')errors.add :current, :must_be_of_the_same_type_as_previous- # i18n-tasks-use t('activemodel.errors.models.time_series/trend.attributes.previous.must_be_of_the_same_type_as_current')errors.add :previous, :must_be_of_the_same_type_as_currentendenddef values_must_be_of_known_typeunless current.is_a?(Money) || current.is_a?(Numeric) || current.nil?- # i18n-tasks-use t('activemodel.errors.models.time_series/trend.attributes.current.must_be_of_type_money_numeric_or_nil')errors.add :current, :must_be_of_type_money_numeric_or_nilendunless previous.is_a?(Money) || previous.is_a?(Numeric) || previous.nil?- # i18n-tasks-use t('activemodel.errors.models.time_series/trend.attributes.previous.must_be_of_type_money_numeric_or_nil')errors.add :previous, :must_be_of_type_money_numeric_or_nilendenddiff --git a/app/models/time_series/value.rb b/app/models/time_series/value.rbindex c02dc3e4..390343e1 100644--- a/app/models/time_series/value.rb+++ b/app/models/time_series/value.rb@@ -40,7 +40,6 @@ class TimeSeries::Valuedef value_must_be_of_known_typeunless value.is_a?(Money) || value.is_a?(Numeric)- # i18n-tasks-use t('activemodel.errors.models.time_series/value.attributes.value.must_be_a_money_or_numeric')errors.add :value, :must_be_a_money_or_numericendenddiff --git a/app/models/user.rb b/app/models/user.rbindex a4a9dd04..7a1cca57 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -55,7 +55,6 @@ class User < ApplicationRecorddef can_deactivateif admin? && family.users.count > 1- # i18n-tasks-use t('activerecord.errors.models.user.attributes.base.cannot_deactivate_admin_with_other_users')errors.add(:base, :cannot_deactivate_admin_with_other_users)endend@@ -84,7 +83,6 @@ class User < ApplicationRecorddef profile_image_sizeif profile_image.attached? && profile_image.byte_size > 5.megabytes- # i18n-tasks-use t('activerecord.errors.models.user.attributes.profile_image.invalid_file_size')errors.add(:profile_image, :invalid_file_size, max_megabytes: 5)endenddiff --git a/app/views/account/transfers/_form.html.erb b/app/views/account/transfers/_form.html.erbindex 84e0b914..3d68dc8a 100644--- a/app/views/account/transfers/_form.html.erb+++ b/app/views/account/transfers/_form.html.erb@@ -30,7 +30,6 @@<%= f.collection_select :from_account_id, Current.family.accounts.alphabetically, :id, :name, { prompt: t(".select_account"), label: t(".from") }, required: true %><%= f.collection_select :to_account_id, Current.family.accounts.alphabetically, :id, :name, { prompt: t(".select_account"), label: t(".to") }, required: true %><%= money_field f, :amount_money, label: t(".amount"), required: true %>- <%= f.hidden_field :currency, value: Current.family.currency %><%= f.date_field :date, value: transfer.date, label: t(".date"), required: true, max: Date.current %></section>diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.ymlindex 028f9607..67ca3f64 100644--- a/config/i18n-tasks.yml+++ b/config/i18n-tasks.yml@@ -26,6 +26,8 @@ search:ignore_unused:- 'activerecord.attributes.*' # i18n-tasks does not detect these on forms, forms validations (https://github.com/glebm/i18n-tasks/blob/0b4b483c82664f26c5696fb0f6aa1297356e4683/templates/config/i18n-tasks.yml#L146)- 'activerecord.models.*' # i18n-tasks does not detect use in dynamic model names (e.g. object.model_name.human)+ - 'activerecord.errors.models*'+ - 'activemodel.errors.models.*'- 'helpers.submit.*' # i18n-tasks does not detect used at forms- 'helpers.label.*' # i18n-tasks does not detect used at forms- 'accounts.show.sync_message_*' # messages generated in the sync ActiveJobdiff --git a/test/controllers/account/transfers_controller_test.rb b/test/controllers/account/transfers_controller_test.rbindex a41426bf..06289fd5 100644--- a/test/controllers/account/transfers_controller_test.rb+++ b/test/controllers/account/transfers_controller_test.rb@@ -18,7 +18,6 @@ class Account::TransfersControllerTest < ActionDispatch::IntegrationTestto_account_id: accounts(:credit_card).id,date: Date.current,amount: 100,- currency: "USD",name: "Test Transfer"}}