Skip to content

Commit

Permalink
Auto naming of Transfer Transaction (#1393)
Browse files Browse the repository at this point in the history
* Remove Description field

* Auto naming of tranfer transaction

* Fix transfer test

* Improve Transfer entries names
  • Loading branch information
Harry-kp authored Nov 1, 2024
1 parent 2b61821 commit 47288a1
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 9 deletions.
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

0 comments on commit 47288a1

Please sign in to comment.