From bd7624199cafcac7e3ec70d82779ac3507fc38da Mon Sep 17 00:00:00 2001 From: Harshit Chaudhary <55315065+Harry-kp@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:22:59 +0000 Subject: [PATCH 1/4] Remove Description field --- app/views/account/transfers/_form.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/account/transfers/_form.html.erb b/app/views/account/transfers/_form.html.erb index 61fb9350..2d35cef0 100644 --- a/app/views/account/transfers/_form.html.erb +++ b/app/views/account/transfers/_form.html.erb @@ -26,7 +26,6 @@
- <%= 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 %> -- 2.53.0 From 3bb30da9cebedda78274d300b79f0fb4b88b7403 Mon Sep 17 00:00:00 2001 From: Harshit Chaudhary <55315065+Harry-kp@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:23:46 +0000 Subject: [PATCH 2/4] Auto naming of tranfer transaction --- app/models/account/entry.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/models/account/entry.rb b/app/models/account/entry.rb index e04756f1..29ae45ae 100644 --- a/app/models/account/entry.rb +++ b/app/models/account/entry.rb @@ -28,6 +28,8 @@ class Account::Entry < ApplicationRecord .where("er.rate IS NOT NULL OR account_entries.currency = ?", currency) } + before_save :assign_transfer_name, if: -> { marked_as_transfer && transfer.present? } + def sync_account_later if destroyed? sync_start_date = previous_entry&.date @@ -223,4 +225,8 @@ class Account::Entry < ApplicationRecord previous: previous_entry&.amount_money, favorable_direction: account.favorable_direction end + + def assign_transfer_name + self.name = transfer.name + end end -- 2.53.0 From 47efc793f538adbeeb22a5d02d1a12123ee7b7ac Mon Sep 17 00:00:00 2001 From: Harshit Chaudhary <55315065+Harry-kp@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:45:21 +0000 Subject: [PATCH 3/4] Fix transfer test --- config/locales/views/account/transfers/en.yml | 2 -- test/system/transfers_test.rb | 1 - 2 files changed, 3 deletions(-) diff --git a/config/locales/views/account/transfers/en.yml b/config/locales/views/account/transfers/en.yml index 515d28e6..8939c446 100644 --- a/config/locales/views/account/transfers/en.yml +++ b/config/locales/views/account/transfers/en.yml @@ -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 diff --git a/test/system/transfers_test.rb b/test/system/transfers_test.rb index 228c3ab2..1fc72fa5 100644 --- a/test/system/transfers_test.rb +++ b/test/system/transfers_test.rb @@ -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 -- 2.53.0 From 5f24309197b4dd57b178aa3ff44e951bf36da089 Mon Sep 17 00:00:00 2001 From: Harshit Chaudhary <55315065+Harry-kp@users.noreply.github.com> Date: Thu, 31 Oct 2024 18:04:06 +0000 Subject: [PATCH 4/4] Improve Transfer entries names --- app/controllers/account/transfers_controller.rb | 3 +-- app/models/account/entry.rb | 6 ------ app/models/account/transfer.rb | 6 +++--- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/app/controllers/account/transfers_controller.rb b/app/controllers/account/transfers_controller.rb index c8fd4877..bdd611f9 100644 --- a/app/controllers/account/transfers_controller.rb +++ b/app/controllers/account/transfers_controller.rb @@ -14,8 +14,7 @@ class Account::TransfersController < ApplicationController @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) diff --git a/app/models/account/entry.rb b/app/models/account/entry.rb index 29ae45ae..e04756f1 100644 --- a/app/models/account/entry.rb +++ b/app/models/account/entry.rb @@ -28,8 +28,6 @@ class Account::Entry < ApplicationRecord .where("er.rate IS NOT NULL OR account_entries.currency = ?", currency) } - before_save :assign_transfer_name, if: -> { marked_as_transfer && transfer.present? } - def sync_account_later if destroyed? sync_start_date = previous_entry&.date @@ -225,8 +223,4 @@ class Account::Entry < ApplicationRecord previous: previous_entry&.amount_money, favorable_direction: account.favorable_direction end - - def assign_transfer_name - self.name = transfer.name - end end diff --git a/app/models/account/transfer.rb b/app/models/account/transfer.rb index 370d53a2..9cd78ac1 100644 --- a/app/models/account/transfer.rb +++ b/app/models/account/transfer.rb @@ -43,12 +43,12 @@ class Account::Transfer < ApplicationRecord 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 @@ -56,7 +56,7 @@ class Account::Transfer < ApplicationRecord 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 -- 2.53.0