Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto naming of Transfer Transaction #1393

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/controllers/account/transfers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def create
@transfer = Account::Transfer.build_from_accounts from_account, to_account, \
date: transfer_params[:date],
amount: transfer_params[:amount].to_d,
currency: transfer_params[:currency],
name: transfer_params[:name]
currency: transfer_params[:currency]

if @transfer.save
@transfer.entries.each(&:sync_account_later)
Expand Down
6 changes: 3 additions & 3 deletions app/models/account/transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ def destroy_and_remove_marks!
end

class << self
def build_from_accounts(from_account, to_account, date:, amount:, currency:, name:)
def build_from_accounts(from_account, to_account, date:, amount:, currency:)
outflow = from_account.entries.build \
amount: amount.abs,
currency: from_account.currency,
date: date,
name: name,
name: "Transfer to #{to_account.name}",
marked_as_transfer: true,
entryable: Account::Transaction.new

inflow = to_account.entries.build \
amount: amount.abs * -1,
currency: from_account.currency,
date: date,
name: name,
name: "Transfer from #{from_account.name}",
marked_as_transfer: true,
entryable: Account::Transaction.new

Expand Down
1 change: 0 additions & 1 deletion app/views/account/transfers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
</section>

<section class="space-y-2">
<%= f.text_field :name, value: transfer.name, label: t(".description"), placeholder: t(".description_placeholder"), required: true %>
<%= 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 %>
<%= f.money_field :amount, label: t(".amount"), required: true, hide_currency: true %>
Expand Down
2 changes: 0 additions & 2 deletions config/locales/views/account/transfers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ en:
form:
amount: Amount
date: Date
description: Description
description_placeholder: Transfer from Checking to Savings
expense: Expense
from: From
income: Income
Expand Down
1 change: 0 additions & 1 deletion test/system/transfers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class TransfersTest < ApplicationSystemTestCase
click_on "Transfer"
assert_text "New transfer"

fill_in "Description", with: "Transfer txn name"
select checking_name, from: "From"
select savings_name, from: "To"
fill_in "account_transfer[amount]", with: 500
Expand Down