The personal finance app for everyone
Add tags selection and notes input to new transaction form (#2008)
Tony Vincent48c8499b7021
diff --git a/app/controllers/account/transactions_controller.rb b/app/controllers/account/transactions_controller.rbindex 028fd5d0..8125565c 100644--- a/app/controllers/account/transactions_controller.rb+++ b/app/controllers/account/transactions_controller.rb@@ -27,7 +27,7 @@ class Account::TransactionsController < ApplicationControllerenddef bulk_update_params- params.require(:bulk_update).permit(:date, :notes, :category_id, :merchant_id, entry_ids: [])+ params.require(:bulk_update).permit(:date, :notes, :category_id, :merchant_id, entry_ids: [], tag_ids: [])enddef search_paramsdiff --git a/app/models/account/entry.rb b/app/models/account/entry.rbindex b53db19b..4e6292a1 100644--- a/app/models/account/entry.rb+++ b/app/models/account/entry.rb@@ -67,7 +67,8 @@ class Account::Entry < ApplicationRecordnotes: bulk_update_params[:notes],entryable_attributes: {category_id: bulk_update_params[:category_id],- merchant_id: bulk_update_params[:merchant_id]+ merchant_id: bulk_update_params[:merchant_id],+ tag_ids: bulk_update_params[:tag_ids]}.compact_blank}.compact_blankdiff --git a/app/views/account/transactions/_form.html.erb b/app/views/account/transactions/_form.html.erbindex fd8d404c..211738c5 100644--- a/app/views/account/transactions/_form.html.erb+++ b/app/views/account/transactions/_form.html.erb@@ -31,6 +31,24 @@<%= f.date_field :date, label: t(".date"), required: true, min: Account::Entry.min_supported_date, max: Date.current, value: Date.current %></section>+ <%= disclosure t(".details"), default_open: false do %>+ <%= f.fields_for :entryable do |ef| %>+ <%= ef.select :tag_ids,+ Current.family.tags.alphabetically.pluck(:name, :id),+ {+ include_blank: t(".none"),+ multiple: true,+ label: t(".tags_label"),+ container_class: "h-40"+ }%>+ <% end %>+ <%= f.text_area :notes,+ label: t(".note_label"),+ placeholder: t(".note_placeholder"),+ rows: 5,+ "data-auto-submit-form-target": "auto" %>+ <% end %>+<section><%= f.submit t(".submit") %></section>diff --git a/app/views/account/transactions/bulk_edit.html.erb b/app/views/account/transactions/bulk_edit.html.erbindex c42faf50..7c0a7e0f 100644--- a/app/views/account/transactions/bulk_edit.html.erb+++ b/app/views/account/transactions/bulk_edit.html.erb@@ -40,6 +40,7 @@<div class="space-y-2"><%= form.collection_select :category_id, Current.family.categories.alphabetically, :id, :name, { prompt: t(".category_placeholder"), label: t(".category_label"), class: "text-subdued" } %><%= form.collection_select :merchant_id, Current.family.merchants.alphabetically, :id, :name, { prompt: t(".merchant_placeholder"), label: t(".merchant_label"), class: "text-subdued" } %>+ <%= form.select :tag_ids, Current.family.tags.alphabetically.pluck(:name, :id), { include_blank: t(".none"), multiple: true, label: t(".tag_label"), container_class: "h-40" } %><%= form.text_area :notes, label: t(".note_label"), placeholder: t(".note_placeholder"), rows: 5 %></div></details>diff --git a/config/locales/views/account/transactions/en.yml b/config/locales/views/account/transactions/en.ymlindex 397c7bb5..a5f979e3 100644--- a/config/locales/views/account/transactions/en.yml+++ b/config/locales/views/account/transactions/en.yml@@ -12,10 +12,12 @@ en:details: Detailsmerchant_label: Merchantmerchant_placeholder: Select a merchant+ none: (none)note_label: Notesnote_placeholder: Enter a note that will be applied to selected transactionsoverview: Overviewsave: Save+ tag_label: Tagsbulk_update:success: "%{count} transactions updated"form:@@ -29,7 +31,11 @@ en:description_placeholder: Describe transactionexpense: Expenseincome: Income+ none: (none)+ note_label: Notes+ note_placeholder: Enter a notesubmit: Add transaction+ tags_label: Tagstransfer: Transfernew:new_transaction: New transactiondiff --git a/test/controllers/account/transactions_controller_test.rb b/test/controllers/account/transactions_controller_test.rbindex d490bfa7..bb1d9b83 100644--- a/test/controllers/account/transactions_controller_test.rb+++ b/test/controllers/account/transactions_controller_test.rb@@ -99,6 +99,7 @@ class Account::TransactionsControllerTest < ActionDispatch::IntegrationTestdate: 1.day.ago.to_date,category_id: Category.second.id,merchant_id: Merchant.second.id,+ tag_ids: [ Tag.first.id, Tag.second.id ],notes: "Updated note"}}@@ -112,6 +113,7 @@ class Account::TransactionsControllerTest < ActionDispatch::IntegrationTestassert_equal Category.second, transaction.account_transaction.categoryassert_equal Merchant.second, transaction.account_transaction.merchantassert_equal "Updated note", transaction.notes+ assert_equal [ Tag.first.id, Tag.second.id ], transaction.entryable.tag_ids.sortendendend