diff --git a/app/controllers/account/transactions_controller.rb b/app/controllers/account/transactions_controller.rb
index 028fd5d0..8125565c 100644
--- a/app/controllers/account/transactions_controller.rb
+++ b/app/controllers/account/transactions_controller.rb
@@ -27,7 +27,7 @@ class Account::TransactionsController < ApplicationController
end
def 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: [])
end
def search_params
diff --git a/app/models/account/entry.rb b/app/models/account/entry.rb
index b53db19b..4e6292a1 100644
--- a/app/models/account/entry.rb
+++ b/app/models/account/entry.rb
@@ -67,7 +67,8 @@ class Account::Entry < ApplicationRecord
notes: 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_blank
diff --git a/app/views/account/transactions/_form.html.erb b/app/views/account/transactions/_form.html.erb
index 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 %>
+ <%= 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 %>
+
<%= f.submit t(".submit") %>
diff --git a/app/views/account/transactions/bulk_edit.html.erb b/app/views/account/transactions/bulk_edit.html.erb
index 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 @@
<%= 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 %>
diff --git a/config/locales/views/account/transactions/en.yml b/config/locales/views/account/transactions/en.yml
index 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: Details
merchant_label: Merchant
merchant_placeholder: Select a merchant
+ none: (none)
note_label: Notes
note_placeholder: Enter a note that will be applied to selected transactions
overview: Overview
save: Save
+ tag_label: Tags
bulk_update:
success: "%{count} transactions updated"
form:
@@ -29,7 +31,11 @@ en:
description_placeholder: Describe transaction
expense: Expense
income: Income
+ none: (none)
+ note_label: Notes
+ note_placeholder: Enter a note
submit: Add transaction
+ tags_label: Tags
transfer: Transfer
new:
new_transaction: New transaction
diff --git a/test/controllers/account/transactions_controller_test.rb b/test/controllers/account/transactions_controller_test.rb
index 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::IntegrationTest
date: 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::IntegrationTest
assert_equal Category.second, transaction.account_transaction.category
assert_equal Merchant.second, transaction.account_transaction.merchant
assert_equal "Updated note", transaction.notes
+ assert_equal [ Tag.first.id, Tag.second.id ], transaction.entryable.tag_ids.sort
end
end
end