1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-04 04:55:20 +02:00

Auto naming of Transfer Transaction (#1393)

* Remove Description field

* Auto naming of tranfer transaction

* Fix transfer test

* Improve Transfer entries names
This commit is contained in:
Harshit Chaudhary 2024-11-01 18:28:19 +05:30 committed by GitHub
parent 2b61821336
commit 47288a1629
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 4 additions and 9 deletions

View file

@ -14,8 +14,7 @@ class Account::TransfersController < ApplicationController
@transfer = Account::Transfer.build_from_accounts from_account, to_account, \ @transfer = Account::Transfer.build_from_accounts from_account, to_account, \
date: transfer_params[:date], date: transfer_params[:date],
amount: transfer_params[:amount].to_d, amount: transfer_params[:amount].to_d,
currency: transfer_params[:currency], currency: transfer_params[:currency]
name: transfer_params[:name]
if @transfer.save if @transfer.save
@transfer.entries.each(&:sync_account_later) @transfer.entries.each(&:sync_account_later)

View file

@ -43,12 +43,12 @@ class Account::Transfer < ApplicationRecord
end end
class << self 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 \ outflow = from_account.entries.build \
amount: amount.abs, amount: amount.abs,
currency: from_account.currency, currency: from_account.currency,
date: date, date: date,
name: name, name: "Transfer to #{to_account.name}",
marked_as_transfer: true, marked_as_transfer: true,
entryable: Account::Transaction.new entryable: Account::Transaction.new
@ -56,7 +56,7 @@ class Account::Transfer < ApplicationRecord
amount: amount.abs * -1, amount: amount.abs * -1,
currency: from_account.currency, currency: from_account.currency,
date: date, date: date,
name: name, name: "Transfer from #{from_account.name}",
marked_as_transfer: true, marked_as_transfer: true,
entryable: Account::Transaction.new entryable: Account::Transaction.new

View file

@ -26,7 +26,6 @@
</section> </section>
<section class="space-y-2"> <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 :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.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 %> <%= f.money_field :amount, label: t(".amount"), required: true, hide_currency: true %>

View file

@ -9,8 +9,6 @@ en:
form: form:
amount: Amount amount: Amount
date: Date date: Date
description: Description
description_placeholder: Transfer from Checking to Savings
expense: Expense expense: Expense
from: From from: From
income: Income income: Income

View file

@ -17,7 +17,6 @@ class TransfersTest < ApplicationSystemTestCase
click_on "Transfer" click_on "Transfer"
assert_text "New transfer" assert_text "New transfer"
fill_in "Description", with: "Transfer txn name"
select checking_name, from: "From" select checking_name, from: "From"
select savings_name, from: "To" select savings_name, from: "To"
fill_in "account_transfer[amount]", with: 500 fill_in "account_transfer[amount]", with: 500