1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 05:09:38 +02:00

Create tagging system (#792)

* Repro

* Fix

* Update signage

* Create tagging system

* Add tags to transaction imports

* Build tagging UI

* Cleanup

* More cleanup
This commit is contained in:
Zach Gollwitzer 2024-05-23 08:09:33 -04:00 committed by GitHub
parent 41c991384a
commit 457247da8e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 607 additions and 90 deletions

View file

@ -72,8 +72,8 @@ class TransactionsController < ApplicationController
def create
@transaction = Current.family.accounts
.find(params[:transaction][:account_id])
.transactions.build(transaction_params.merge(amount: amount))
.find(params[:transaction][:account_id])
.transactions.build(transaction_params.merge(amount: amount))
respond_to do |format|
if @transaction.save
@ -88,11 +88,20 @@ class TransactionsController < ApplicationController
def update
respond_to do |format|
sync_start_date = if transaction_params[:date]
[ @transaction.date, Date.parse(transaction_params[:date]) ].compact.min
[ @transaction.date, Date.parse(transaction_params[:date]) ].compact.min
else
@transaction.date
end
if params[:transaction][:tag_id].present?
tag = Current.family.tags.find(params[:transaction][:tag_id])
@transaction.tags << tag unless @transaction.tags.include?(tag)
end
if params[:transaction][:remove_tag_id].present?
@transaction.tags.delete(params[:transaction][:remove_tag_id])
end
if @transaction.update(transaction_params)
@transaction.account.sync_later(sync_start_date)
@ -121,6 +130,7 @@ class TransactionsController < ApplicationController
end
private
def delete_search_param(params, key, value: nil)
if value
params[key]&.delete(value)
@ -153,8 +163,7 @@ class TransactionsController < ApplicationController
params[:transaction][:nature].to_s.inquiry
end
# Only allow a list of trusted parameters through.
def transaction_params
params.require(:transaction).permit(:name, :date, :amount, :currency, :notes, :excluded, :category_id, :merchant_id)
params.require(:transaction).permit(:name, :date, :amount, :currency, :notes, :excluded, :category_id, :merchant_id, :tag_id, :remove_tag_id).except(:tag_id, :remove_tag_id)
end
end