The personal finance app for everyone (by everyone)
Ruby
fix: derive amount_abs from inflow entry to avoid $0.00 regression on auto-matched transfers
DataEnginr9b6a966ddb27
diff --git a/app/models/transfer.rb b/app/models/transfer.rbindex 2e551e4cdc..60f0f3128e 100644--- a/app/models/transfer.rb+++ b/app/models/transfer.rb@@ -12,7 +12,7 @@ class Transfer < ApplicationRecordvalidates :outflow_transaction_id, uniqueness: truevalidate :transfer_has_different_accounts- validate :transfer_has_opposite_amounts_or_fees+ validate :transfer_has_opposite_amountsvalidate :transfer_within_date_rangevalidate :transfer_has_same_family@@ -57,7 +57,7 @@ class Transfer < ApplicationRecordenddef amount_abs- Money.new(amount || 0, from_account&.currency || "USD")+ inflow_transaction&.entry&.amount_money&.abs || Money.new(0, from_account&.currency || "USD")enddef name@@ -151,7 +151,7 @@ class Transfer < ApplicationRecorderrors.add(:base, :same_family) unless to_account&.family == from_account&.familyend- def transfer_has_opposite_amounts_or_fees+ def transfer_has_opposite_amountsreturn unless inflow_transaction&.entry && outflow_transaction&.entryinflow_entry = inflow_transaction.entrydiff --git a/config/locales/views/transfers/en.yml b/config/locales/views/transfers/en.ymlindex 7a6ba74fc4..8c483e8720 100644--- a/config/locales/views/transfers/en.yml+++ b/config/locales/views/transfers/en.yml@@ -10,8 +10,6 @@ en:bank_charges: Bank Chargesoutgoing_fee: Outgoing transfer feeincoming_fee: Incoming transfer fee- calculate_rate_tab: Calculate FX rate- convert_tab: Convert with FX ratedate: Datedestination_amount: Destination amountdestination_amount_display: "Destination amount: %{amount}"diff --git a/spec/requests/api/v1/transfers_spec.rb b/spec/requests/api/v1/transfers_spec.rbindex 47fcdd8230..0afcfe70e1 100644--- a/spec/requests/api/v1/transfers_spec.rb+++ b/spec/requests/api/v1/transfers_spec.rb@@ -139,7 +139,13 @@ RSpec.describe 'API V1 Transfers', type: :request doresponse '200', 'transfer retrieved' doschema '$ref' => '#/components/schemas/TransferDecision'- run_test!+ run_test! do |response|+ body = JSON.parse(response.body)+ expect(body['source_fee_amount']).to eq '0.0'+ expect(body['destination_fee_amount']).to eq '0.0'+ expect(body).to have_key('source_fee_currency')+ expect(body).to have_key('destination_fee_currency')+ endendresponse '401', 'unauthorized' dodiff --git a/test/controllers/api/v1/transfers_controller_test.rb b/test/controllers/api/v1/transfers_controller_test.rbindex e74dcfbda8..1724357219 100644--- a/test/controllers/api/v1/transfers_controller_test.rb+++ b/test/controllers/api/v1/transfers_controller_test.rb@@ -82,6 +82,10 @@ class Api::V1::TransfersControllerTest < ActionDispatch::IntegrationTestassert_equal "Transfer Savings", response_data.dig("inflow_transaction", "account", "name")assert_equal "Transfer Checking", response_data.dig("outflow_transaction", "account", "name")assert response_data.key?("amount_cents")+ assert_equal "0.0", response_data["source_fee_amount"]+ assert_equal "0.0", response_data["destination_fee_amount"]+ assert response_data.key?("source_fee_currency")+ assert response_data.key?("destination_fee_currency")endtest "returns not found for another family's transfer" do