Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Add transfer fee support for bank charges on account-to-account transfers

Shibu Me73006af54c3
diff --git a/app/controllers/transfers_controller.rb b/app/controllers/transfers_controller.rb
index 465891f2f4..b52870c914 100644
--- a/app/controllers/transfers_controller.rb
+++ b/app/controllers/transfers_controller.rb
@@ -38,7 +38,9 @@ class TransfersController < ApplicationController
destination_account_id: destination_account.id,
date: transfer_params[:date].present? ? Date.parse(transfer_params[:date]) : Date.current,
amount: transfer_params[:amount].to_d,
- exchange_rate: transfer_params[:exchange_rate].presence&.to_d
+ exchange_rate: transfer_params[:exchange_rate].presence&.to_d,
+ source_fee_amount: transfer_params[:source_fee_amount],
+ destination_fee_amount: transfer_params[:destination_fee_amount]
).create
if @transfer.persisted?
@@ -160,7 +162,7 @@ class TransfersController < ApplicationController
end
def transfer_params
- params.require(:transfer).permit(:from_account_id, :to_account_id, :amount, :date, :name, :excluded, :exchange_rate)
+ params.require(:transfer).permit(:from_account_id, :to_account_id, :amount, :date, :name, :excluded, :exchange_rate, :source_fee_amount, :destination_fee_amount)
end
def set_accounts
diff --git a/app/models/transfer.rb b/app/models/transfer.rb
index 9b39d0f7d9..7d5c449470 100644
--- a/app/models/transfer.rb
+++ b/app/models/transfer.rb
@@ -8,7 +8,7 @@ class Transfer < ApplicationRecord
validates :outflow_transaction_id, uniqueness: true
validate :transfer_has_different_accounts
- validate :transfer_has_opposite_amounts
+ validate :transfer_has_opposite_amounts_or_fees
validate :transfer_within_date_range
validate :transfer_has_same_family
@@ -28,6 +28,22 @@ class Transfer < ApplicationRecord
end
end
+ def has_source_fee?
+ source_fee_amount.to_d > 0
+ end
+
+ def has_destination_fee?
+ destination_fee_amount.to_d > 0
+ end
+
+ def has_fees?
+ has_source_fee? || has_destination_fee?
+ end
+
+ def total_fee
+ source_fee_amount.to_d + destination_fee_amount.to_d
+ end
+
def reject!
Transfer.transaction do
RejectedTransfer.find_or_create_by!(inflow_transaction_id: inflow_transaction_id, outflow_transaction_id: outflow_transaction_id)
@@ -123,7 +139,7 @@ class Transfer < ApplicationRecord
errors.add(:base, :same_family) unless to_account&.family == from_account&.family
end
- def transfer_has_opposite_amounts
+ def transfer_has_opposite_amounts_or_fees
return unless inflow_transaction&.entry && outflow_transaction&.entry
inflow_entry = inflow_transaction.entry
@@ -133,10 +149,9 @@ class Transfer < ApplicationRecord
outflow_amount = outflow_entry.amount
if inflow_entry.currency == outflow_entry.currency
- # For same currency, amounts must be exactly opposite
- errors.add(:base, :opposite_amounts) if inflow_amount + outflow_amount != 0
+ total_fee = source_fee_amount.to_d + destination_fee_amount.to_d
+ errors.add(:base, :opposite_amounts) if inflow_amount + outflow_amount != total_fee
else
- # For different currencies, just check the signs are opposite
errors.add(:base, :opposite_amounts) unless inflow_amount.negative? && outflow_amount.positive?
end
end
diff --git a/app/models/transfer/creator.rb b/app/models/transfer/creator.rb
index 7aa8bc72cf..3d31e3bcdf 100644
--- a/app/models/transfer/creator.rb
+++ b/app/models/transfer/creator.rb
@@ -1,10 +1,12 @@
class Transfer::Creator
- def initialize(family:, source_account_id:, destination_account_id:, date:, amount:, exchange_rate: nil)
+ def initialize(family:, source_account_id:, destination_account_id:, date:, amount:, exchange_rate: nil, source_fee_amount: nil, destination_fee_amount: nil)
@family = family
@source_account = family.accounts.find(source_account_id) # early throw if not found
@destination_account = family.accounts.find(destination_account_id) # early throw if not found
@date = date
@amount = amount.to_d
+ @source_fee_amount = source_fee_amount.to_d
+ @destination_fee_amount = destination_fee_amount.to_d
if exchange_rate.present?
rate_value = exchange_rate.to_d
@@ -19,7 +21,9 @@ class Transfer::Creator
transfer = Transfer.new(
inflow_transaction: inflow_transaction,
outflow_transaction: outflow_transaction,
- status: "confirmed"
+ status: "confirmed",
+ source_fee_amount: source_fee_amount,
+ destination_fee_amount: destination_fee_amount
)
if transfer.save
@@ -31,7 +35,7 @@ class Transfer::Creator
end
private
- attr_reader :family, :source_account, :destination_account, :date, :amount, :exchange_rate
+ attr_reader :family, :source_account, :destination_account, :date, :amount, :exchange_rate, :source_fee_amount, :destination_fee_amount
def outflow_transaction
name = "#{name_prefix} to #{destination_account.name}"
@@ -41,7 +45,7 @@ class Transfer::Creator
kind: kind,
category: (investment_contributions_category if kind == "investment_contribution"),
entry: source_account.entries.build(
- amount: amount.abs,
+ amount: amount.abs + source_fee_amount,
currency: source_account.currency,
date: date,
name: name,
@@ -57,10 +61,12 @@ class Transfer::Creator
def inflow_transaction
name = "#{name_prefix} from #{source_account.name}"
+ net_inflow = inflow_converted_amount - destination_fee_amount
+
Transaction.new(
kind: "funds_movement",
entry: destination_account.entries.build(
- amount: inflow_converted_money.amount.abs * -1,
+ amount: net_inflow * -1,
currency: destination_account.currency,
date: date,
name: name,
@@ -69,15 +75,14 @@ class Transfer::Creator
)
end
- # If destination account has different currency, its transaction should show up as converted
- # Uses user-provided exchange rate if available, otherwise requires a provider rate
- def inflow_converted_money
+ # Converts the transfer amount to the destination currency
+ def inflow_converted_amount
Money.new(amount.abs, source_account.currency)
.exchange_to(
destination_account.currency,
date: date,
custom_rate: exchange_rate
- )
+ ).amount
end
# The "expense" side of a transfer is treated different in analytics based on where it goes.
diff --git a/app/views/api/v1/transfers/_transfer.json.jbuilder b/app/views/api/v1/transfers/_transfer.json.jbuilder
index 1fb27815f1..5c3ddc9b83 100644
--- a/app/views/api/v1/transfers/_transfer.json.jbuilder
+++ b/app/views/api/v1/transfers/_transfer.json.jbuilder
@@ -8,6 +8,10 @@ json.amount_cents money_to_minor_units(transfer.amount_abs)
json.currency transfer.inflow_transaction.entry.currency
json.transfer_type transfer.transfer_type
json.notes transfer.notes
+json.source_fee_amount transfer.source_fee_amount.to_f
+json.source_fee_currency transfer.from_account&.currency
+json.destination_fee_amount transfer.destination_fee_amount.to_f
+json.destination_fee_currency transfer.to_account&.currency
json.inflow_transaction do
json.partial! "api/v1/transfers/transaction_side", transaction: transfer.inflow_transaction
diff --git a/app/views/transfers/_form.html.erb b/app/views/transfers/_form.html.erb
index a7696692a9..e80dfd2ff3 100644
--- a/app/views/transfers/_form.html.erb
+++ b/app/views/transfers/_form.html.erb
@@ -73,6 +73,26 @@
destination_input: destination_input %>
</section>
+ <section>
+ <%= render DS::Disclosure.new(title: t(".bank_fees"), open: false, variant: :inline) do %>
+ <div class="space-y-2 pt-2">
+ <%= f.number_field :source_fee_amount,
+ label: t(".source_fee"),
+ min: 0,
+ placeholder: "0.00",
+ step: 0.01,
+ data: { transfer_form_target: "sourceFee" } %>
+
+ <%= f.number_field :destination_fee_amount,
+ label: t(".destination_fee"),
+ min: 0,
+ placeholder: "0.00",
+ step: 0.01,
+ data: { transfer_form_target: "destinationFee" } %>
+ </div>
+ <% end %>
+ </section>
+
<section>
<%= f.submit t(".submit") %>
</section>
diff --git a/app/views/transfers/show.html.erb b/app/views/transfers/show.html.erb
index 3512fe5929..6b4a82afda 100644
--- a/app/views/transfers/show.html.erb
+++ b/app/views/transfers/show.html.erb
@@ -38,6 +38,24 @@
<dd class="font-medium text-red-500 privacy-sensitive"><%= format_money @transfer.outflow_transaction.entry.amount_money * -1 %></dd>
</dl>
</div>
+ <% if @transfer.has_source_fee? %>
+ <dl class="flex items-center gap-2 justify-between">
+ <dt class="text-secondary"><%= t(".source_fee") %></dt>
+ <dd class="font-medium text-red-500 privacy-sensitive">
+ -<%= format_money Money.new(@transfer.source_fee_amount, @transfer.from_account.currency) %>
+ </dd>
+ </dl>
+ <% end %>
+
+ <% if @transfer.has_destination_fee? %>
+ <dl class="flex items-center gap-2 justify-between">
+ <dt class="text-secondary"><%= t(".destination_fee") %></dt>
+ <dd class="font-medium text-red-500 privacy-sensitive">
+ -<%= format_money Money.new(@transfer.destination_fee_amount, @transfer.to_account.currency) %>
+ </dd>
+ </dl>
+ <% end %>
+
<%= render "shared/ruler", classes: "my-2" %>
<div class="space-y-3">
<dl class="flex items-center gap-2 justify-between">
diff --git a/config/locales/views/transfers/en.yml b/config/locales/views/transfers/en.yml
index aa9c40104e..168e45f87a 100644
--- a/config/locales/views/transfers/en.yml
+++ b/config/locales/views/transfers/en.yml
@@ -7,11 +7,13 @@ en:
success: Transfer removed
form:
amount: Amount
+ bank_fees: Bank fees
calculate_rate_tab: Calculate FX rate
convert_tab: Convert with FX rate
date: Date
destination_amount: Destination amount
destination_amount_display: "Destination amount: %{amount}"
+ destination_fee: Fee deducted from destination
exchange_rate: Exchange rate
exchange_rate_display: "Exchange rate: %{rate}"
exchange_rate_help: Choose how to enter the transfer amount.
@@ -20,6 +22,7 @@ en:
income: Income
select_account: Select account
source_amount: Source amount
+ source_fee: Fee charged to source
submit: Create transfer
to: To
transfer: Transfer
@@ -43,6 +46,8 @@ en:
to: To
date: Date
amount: Amount
+ source_fee: Source fee
+ destination_fee: Destination fee
category: Category
uncategorized: Uncategorized
update:
diff --git a/db/migrate/20260604000000_add_fees_to_transfers.rb b/db/migrate/20260604000000_add_fees_to_transfers.rb
new file mode 100644
index 0000000000..ca7297971d
--- /dev/null
+++ b/db/migrate/20260604000000_add_fees_to_transfers.rb
@@ -0,0 +1,6 @@
+class AddFeesToTransfers < ActiveRecord::Migration[7.2]
+ def change
+ add_column :transfers, :source_fee_amount, :decimal, precision: 19, scale: 4, null: false, default: 0
+ add_column :transfers, :destination_fee_amount, :decimal, precision: 19, scale: 4, null: false, default: 0
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index c055adbfc2..cf1cadecfc 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -53,6 +53,7 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_31_213000) do
t.string "content_type", limit: 100, null: false
t.bigint "byte_size", null: false
t.string "checksum", limit: 64, null: false
+ t.string "content_sha256"
t.string "source", default: "manual_upload", null: false
t.string "upload_status", default: "stored", null: false
t.string "institution_name_hint", limit: 200
@@ -69,7 +70,6 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_31_213000) do
t.jsonb "sanitized_parser_output", default: {}, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
- t.string "content_sha256"
t.index ["account_id", "period_start_on", "period_end_on"], name: "index_account_statements_on_account_period"
t.index ["account_id"], name: "index_account_statements_on_account_id"
t.index ["family_id", "checksum"], name: "index_account_statements_on_family_checksum"
@@ -301,9 +301,9 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_31_213000) do
t.string "institution_domain"
t.string "institution_url"
t.string "institution_color"
- t.string "status", default: "good", null: false
- t.boolean "scheduled_for_deletion", default: false, null: false
- t.boolean "pending_account_setup", default: false, null: false
+ t.string "status", default: "good"
+ t.boolean "scheduled_for_deletion", default: false
+ t.boolean "pending_account_setup", default: false
t.datetime "sync_start_date"
t.jsonb "raw_payload"
t.text "api_key"
@@ -886,9 +886,9 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_31_213000) do
t.decimal "current_balance", precision: 19, scale: 4
t.decimal "cash_balance", precision: 19, scale: 4
t.jsonb "institution_metadata"
- t.jsonb "raw_holdings_payload", default: []
- t.jsonb "raw_activities_payload", default: {}
- t.jsonb "raw_cash_report_payload", default: []
+ t.jsonb "raw_holdings_payload", default: [], null: false
+ t.jsonb "raw_activities_payload", default: {}, null: false
+ t.jsonb "raw_cash_report_payload", default: [], null: false
t.date "report_date"
t.datetime "last_holdings_sync"
t.datetime "last_activities_sync"
@@ -902,8 +902,8 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_31_213000) do
create_table "ibkr_items", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "family_id", null: false
t.string "name"
- t.string "status", default: "good"
- t.boolean "scheduled_for_deletion", default: false
+ t.string "status", default: "good", null: false
+ t.boolean "scheduled_for_deletion", default: false, null: false
t.boolean "pending_account_setup", default: false, null: false
t.jsonb "raw_payload"
t.string "query_id"
@@ -1942,6 +1942,7 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_31_213000) do
t.string "external_id"
t.jsonb "extra", default: {}, null: false
t.string "investment_activity_label"
+ t.uuid "refund_of_transaction_id"
t.index "(((extra -> 'goal'::text) ->> 'pledge_id'::text))", name: "ix_transactions_extra_goal_pledge_id", unique: true, where: "(((extra -> 'goal'::text) ->> 'pledge_id'::text) IS NOT NULL)"
t.index ["category_id"], name: "index_transactions_on_category_id"
t.index ["external_id"], name: "index_transactions_on_external_id"
@@ -1949,6 +1950,7 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_31_213000) do
t.index ["investment_activity_label"], name: "index_transactions_on_investment_activity_label"
t.index ["kind"], name: "index_transactions_on_kind"
t.index ["merchant_id"], name: "index_transactions_on_merchant_id"
+ t.index ["refund_of_transaction_id"], name: "index_transactions_on_refund_of_transaction_id"
end
create_table "transfers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
@@ -1958,6 +1960,8 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_31_213000) do
t.text "notes"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.decimal "source_fee_amount", precision: 19, scale: 4, default: "0.0", null: false
+ t.decimal "destination_fee_amount", precision: 19, scale: 4, default: "0.0", null: false
t.index ["inflow_transaction_id", "outflow_transaction_id"], name: "idx_on_inflow_transaction_id_outflow_transaction_id_8cd07a28bd", unique: true
t.index ["inflow_transaction_id"], name: "index_transfers_on_inflow_transaction_id"
t.index ["outflow_transaction_id"], name: "index_transfers_on_outflow_transaction_id"
@@ -2157,6 +2161,7 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_31_213000) do
add_foreign_key "trades", "securities"
add_foreign_key "transactions", "categories", on_delete: :nullify
add_foreign_key "transactions", "merchants"
+ add_foreign_key "transactions", "transactions", column: "refund_of_transaction_id", on_delete: :nullify
add_foreign_key "transfers", "transactions", column: "inflow_transaction_id", on_delete: :cascade
add_foreign_key "transfers", "transactions", column: "outflow_transaction_id", on_delete: :cascade
add_foreign_key "users", "accounts", column: "default_account_id", on_delete: :nullify
diff --git a/spec/swagger_helper.rb b/spec/swagger_helper.rb
index 22c3dd0ccd..a8dee39462 100644
--- a/spec/swagger_helper.rb
+++ b/spec/swagger_helper.rb
@@ -850,6 +850,10 @@ RSpec.configure do |config|
currency: { type: :string },
transfer_type: { type: :string, enum: %w[transfer liability_payment loan_payment] },
notes: { type: :string, nullable: true },
+ source_fee_amount: { type: :number, nullable: true, description: 'Fee charged to the source account' },
+ source_fee_currency: { type: :string, nullable: true },
+ destination_fee_amount: { type: :number, nullable: true, description: 'Fee deducted from the destination account' },
+ destination_fee_currency: { type: :string, nullable: true },
inflow_transaction: { '$ref' => '#/components/schemas/TransferTransactionSide' },
outflow_transaction: { '$ref' => '#/components/schemas/TransferTransactionSide' },
created_at: { type: :string, format: :'date-time' },
diff --git a/test/controllers/transfers_controller_test.rb b/test/controllers/transfers_controller_test.rb
index 544b100572..1da827e1e5 100644
--- a/test/controllers/transfers_controller_test.rb
+++ b/test/controllers/transfers_controller_test.rb
@@ -150,6 +150,73 @@ class TransfersControllerTest < ActionDispatch::IntegrationTest
assert_response :unprocessable_entity
end
+ test "can create transfer with source fee" do
+ assert_difference "Transfer.count", 1 do
+ post transfers_url, params: {
+ transfer: {
+ from_account_id: accounts(:depository).id,
+ to_account_id: accounts(:credit_card).id,
+ date: Date.current,
+ amount: 100,
+ source_fee_amount: 3
+ }
+ }
+ end
+
+ transfer = Transfer.last
+ assert_equal 3, transfer.source_fee_amount
+ assert_equal 0, transfer.destination_fee_amount
+ # Outflow should be amount + source_fee = 100 + 3 = 103
+ assert_equal 103, transfer.outflow_transaction.entry.amount
+ # Inflow should be -(amount - destination_fee) = -(100 - 0) = -100
+ assert_equal(-100, transfer.inflow_transaction.entry.amount)
+ end
+
+ test "can create transfer with destination fee" do
+ assert_difference "Transfer.count", 1 do
+ post transfers_url, params: {
+ transfer: {
+ from_account_id: accounts(:depository).id,
+ to_account_id: accounts(:credit_card).id,
+ date: Date.current,
+ amount: 100,
+ destination_fee_amount: 3
+ }
+ }
+ end
+
+ transfer = Transfer.last
+ assert_equal 0, transfer.source_fee_amount
+ assert_equal 3, transfer.destination_fee_amount
+ # Outflow should be amount + source_fee = 100 + 0 = 100
+ assert_equal 100, transfer.outflow_transaction.entry.amount
+ # Inflow should be -(amount - destination_fee) = -(100 - 3) = -97
+ assert_equal(-97, transfer.inflow_transaction.entry.amount)
+ end
+
+ test "can create transfer with both source and destination fees" do
+ assert_difference "Transfer.count", 1 do
+ post transfers_url, params: {
+ transfer: {
+ from_account_id: accounts(:depository).id,
+ to_account_id: accounts(:credit_card).id,
+ date: Date.current,
+ amount: 100,
+ source_fee_amount: 2,
+ destination_fee_amount: 3
+ }
+ }
+ end
+
+ transfer = Transfer.last
+ assert_equal 2, transfer.source_fee_amount
+ assert_equal 3, transfer.destination_fee_amount
+ # Outflow = 100 + 2 = 102
+ assert_equal 102, transfer.outflow_transaction.entry.amount
+ # Inflow = -(100 - 3) = -97
+ assert_equal(-97, transfer.inflow_transaction.entry.amount)
+ end
+
test "exchange_rate endpoint returns same_currency for matching currencies" do
get exchange_rate_url, params: {
from: "USD",
diff --git a/test/models/transfer_test.rb b/test/models/transfer_test.rb
index e47d200d27..f592930964 100644
--- a/test/models/transfer_test.rb
+++ b/test/models/transfer_test.rb
@@ -124,4 +124,83 @@ class TransferTest < ActiveSupport::TestCase
test "kind_for_account returns funds_movement for depository accounts" do
assert_equal "funds_movement", Transfer.kind_for_account(accounts(:depository))
end
+
+ test "transfer with source fee adjusts validation" do
+ outflow_entry = create_transaction(date: Date.current, account: accounts(:depository), amount: 100)
+ inflow_entry = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -97)
+
+ transfer = Transfer.new(
+ inflow_transaction: inflow_entry.transaction,
+ outflow_transaction: outflow_entry.transaction,
+ source_fee_amount: 3
+ )
+
+ assert transfer.valid?
+ end
+
+ test "transfer with destination fee adjusts validation" do
+ outflow_entry = create_transaction(date: Date.current, account: accounts(:depository), amount: 100)
+ inflow_entry = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -97)
+
+ transfer = Transfer.new(
+ inflow_transaction: inflow_entry.transaction,
+ outflow_transaction: outflow_entry.transaction,
+ destination_fee_amount: 3
+ )
+
+ assert transfer.valid?
+ end
+
+ test "transfer with both source and destination fees adjusts validation" do
+ outflow_entry = create_transaction(date: Date.current, account: accounts(:depository), amount: 103)
+ inflow_entry = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -97)
+
+ transfer = Transfer.new(
+ inflow_transaction: inflow_entry.transaction,
+ outflow_transaction: outflow_entry.transaction,
+ source_fee_amount: 3,
+ destination_fee_amount: 6
+ )
+
+ assert transfer.valid?
+ end
+
+ test "transfer with wrong fee amount fails validation" do
+ outflow_entry = create_transaction(date: Date.current, account: accounts(:depository), amount: 100)
+ inflow_entry = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -95)
+
+ transfer = Transfer.new(
+ inflow_transaction: inflow_entry.transaction,
+ outflow_transaction: outflow_entry.transaction,
+ source_fee_amount: 3
+ )
+
+ assert transfer.invalid?
+ assert_equal "Must have opposite amounts", transfer.errors.full_messages.first
+ end
+
+ test "has_source_fee? returns true when source fee present" do
+ transfer = transfers(:one)
+ transfer.update!(source_fee_amount: 5)
+ assert transfer.has_source_fee?
+ assert transfer.has_fees?
+ end
+
+ test "has_destination_fee? returns true when destination fee present" do
+ transfer = transfers(:one)
+ transfer.update!(destination_fee_amount: 5)
+ assert transfer.has_destination_fee?
+ assert transfer.has_fees?
+ end
+
+ test "has_fees? returns false when no fees" do
+ transfer = transfers(:one)
+ refute transfer.has_fees?
+ end
+
+ test "total_fee sums source and destination fees" do
+ transfer = transfers(:one)
+ transfer.update!(source_fee_amount: 3, destination_fee_amount: 2)
+ assert_equal 5, transfer.total_fee
+ end
end
diff --git a/test/support/entries_test_helper.rb b/test/support/entries_test_helper.rb
index 90ecd92208..e4f1a230f4 100644
--- a/test/support/entries_test_helper.rb
+++ b/test/support/entries_test_helper.rb
@@ -52,20 +52,24 @@ module EntriesTestHelper
entryable: trade
end
- def create_transfer(from_account:, to_account:, amount:, date: Date.current, currency: "USD")
+ def create_transfer(from_account:, to_account:, amount:, date: Date.current, currency: "USD", source_fee_amount: 0, destination_fee_amount: 0)
outflow_transaction = Transaction.create!(kind: "funds_movement")
inflow_transaction = Transaction.create!(kind: "funds_movement")
transfer = Transfer.create!(
outflow_transaction: outflow_transaction,
- inflow_transaction: inflow_transaction
+ inflow_transaction: inflow_transaction,
+ source_fee_amount: source_fee_amount,
+ destination_fee_amount: destination_fee_amount
)
- # Create entries for both accounts
+ total_outflow = amount.abs + source_fee_amount.to_d
+ net_inflow = amount.abs - destination_fee_amount.to_d
+
from_account.entries.create!(
name: "Transfer to #{to_account.name}",
date: date,
- amount: -amount.abs,
+ amount: -total_outflow,
currency: currency,
entryable: outflow_transaction
)
@@ -73,7 +77,7 @@ module EntriesTestHelper
to_account.entries.create!(
name: "Transfer from #{from_account.name}",
date: date,
- amount: amount.abs,
+ amount: net_inflow,
currency: currency,
entryable: inflow_transaction
)