Skip to content

armgit / sure

Public Imported from GitHub
0

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.rb
index 2e551e4cdc..60f0f3128e 100644
--- a/app/models/transfer.rb
+++ b/app/models/transfer.rb
@@ -12,7 +12,7 @@ class Transfer < ApplicationRecord
validates :outflow_transaction_id, uniqueness: true
validate :transfer_has_different_accounts
- validate :transfer_has_opposite_amounts_or_fees
+ validate :transfer_has_opposite_amounts
validate :transfer_within_date_range
validate :transfer_has_same_family
@@ -57,7 +57,7 @@ class Transfer < ApplicationRecord
end
def amount_abs
- Money.new(amount || 0, from_account&.currency || "USD")
+ inflow_transaction&.entry&.amount_money&.abs || Money.new(0, from_account&.currency || "USD")
end
def name
@@ -151,7 +151,7 @@ class Transfer < ApplicationRecord
errors.add(:base, :same_family) unless to_account&.family == from_account&.family
end
- def transfer_has_opposite_amounts_or_fees
+ def transfer_has_opposite_amounts
return unless inflow_transaction&.entry && outflow_transaction&.entry
inflow_entry = inflow_transaction.entry
diff --git a/config/locales/views/transfers/en.yml b/config/locales/views/transfers/en.yml
index 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 Charges
outgoing_fee: Outgoing transfer fee
incoming_fee: Incoming transfer fee
- calculate_rate_tab: Calculate FX rate
- convert_tab: Convert with FX rate
date: Date
destination_amount: Destination amount
destination_amount_display: "Destination amount: %{amount}"
diff --git a/spec/requests/api/v1/transfers_spec.rb b/spec/requests/api/v1/transfers_spec.rb
index 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 do
response '200', 'transfer retrieved' do
schema '$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')
+ end
end
response '401', 'unauthorized' do
diff --git a/test/controllers/api/v1/transfers_controller_test.rb b/test/controllers/api/v1/transfers_controller_test.rb
index 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::IntegrationTest
assert_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")
end
test "returns not found for another family's transfer" do