From 540d7bb4bd772c23b02268a2a6545c7d9bbd5ed6 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Fri, 23 May 2025 18:26:49 -0400 Subject: [PATCH] Disable edits for certain transaction fields for Plaid transactions --- app/models/entry.rb | 4 ++++ app/models/plaid_item.rb | 30 ------------------------- app/models/plaid_item/syncer.rb | 2 +- app/views/shared/_money_field.html.erb | 1 + app/views/trades/_header.html.erb | 6 +++++ app/views/trades/show.html.erb | 10 ++++++--- app/views/transactions/_header.html.erb | 6 +++++ app/views/transactions/show.html.erb | 7 ++++-- 8 files changed, 30 insertions(+), 36 deletions(-) diff --git a/app/models/entry.rb b/app/models/entry.rb index 5b14987a..0426c9f5 100644 --- a/app/models/entry.rb +++ b/app/models/entry.rb @@ -56,6 +56,10 @@ class Entry < ApplicationRecord Balance::TrendCalculator.new(self, entries, balances).trend end + def linked? + plaid_id.present? + end + class << self def search(params) EntrySearch.new(params).build_query(all) diff --git a/app/models/plaid_item.rb b/app/models/plaid_item.rb index cb524fd1..ce828288 100644 --- a/app/models/plaid_item.rb +++ b/app/models/plaid_item.rb @@ -103,36 +103,6 @@ class PlaidItem < ApplicationRecord save! end - # def auto_match_categories! - # if family.categories.none? - # family.categories.bootstrap! - # end - - # alias_matcher = build_category_alias_matcher(family.categories) - - # accounts.each do |account| - # matchable_transactions = account.transactions - # .where(category_id: nil) - # .where.not(plaid_category: nil) - # .enrichable(:category_id) - - # matchable_transactions.each do |transaction| - # category = alias_matcher.match(transaction.plaid_category_detailed) - - # if category.present? - # # Matcher could either return a string or a Category object - # user_category = if category.is_a?(String) - # family.categories.find_or_create_by!(name: category) - # else - # category - # end - - # transaction.enrich_attribute(:category_id, user_category.id, source: "plaid") - # end - # end - # end - # end - def supports_product?(product) supported_products.include?(product) end diff --git a/app/models/plaid_item/syncer.rb b/app/models/plaid_item/syncer.rb index fe0fbd7f..99fec809 100644 --- a/app/models/plaid_item/syncer.rb +++ b/app/models/plaid_item/syncer.rb @@ -21,7 +21,7 @@ class PlaidItem::Syncer end def perform_post_sync - plaid_item.auto_match_categories! + # no-op end private diff --git a/app/views/shared/_money_field.html.erb b/app/views/shared/_money_field.html.erb index ac8e6e55..3f427c71 100644 --- a/app/views/shared/_money_field.html.erb +++ b/app/views/shared/_money_field.html.erb @@ -34,6 +34,7 @@ min: options[:min] || -99999999999999, max: options[:max] || 99999999999999, step: currency.step, + disabled: options[:disabled], data: { "money-field-target": "amount", "auto-submit-form-target": ("auto" if options[:auto_submit]) diff --git a/app/views/trades/_header.html.erb b/app/views/trades/_header.html.erb index 7fcf1a47..5a8515c7 100644 --- a/app/views/trades/_header.html.erb +++ b/app/views/trades/_header.html.erb @@ -16,6 +16,12 @@ <%= entry.currency %> + + <% if entry.linked? %> + + <%= icon("refresh-ccw", size: "sm") %> + + <% end %> diff --git a/app/views/trades/show.html.erb b/app/views/trades/show.html.erb index 97c48e2d..2c7dd392 100644 --- a/app/views/trades/show.html.erb +++ b/app/views/trades/show.html.erb @@ -15,20 +15,22 @@ <%= f.date_field :date, label: t(".date_label"), max: Date.current, + disabled: @entry.linked?, "data-auto-submit-form-target": "auto" %>
<%= f.select :nature, [["Buy", "outflow"], ["Sell", "inflow"]], { container_class: "w-1/3", label: "Type", selected: @entry.amount.negative? ? "inflow" : "outflow" }, - { data: { "auto-submit-form-target": "auto" } } %> + { data: { "auto-submit-form-target": "auto" }, disabled: @entry.linked? } %> <%= f.fields_for :entryable do |ef| %> <%= ef.number_field :qty, label: t(".quantity_label"), step: "any", value: trade.qty.abs, - "data-auto-submit-form-target": "auto" %> + "data-auto-submit-form-target": "auto", + disabled: @entry.linked? %> <% end %>
@@ -37,7 +39,9 @@ label: t(".cost_per_share_label"), disable_currency: true, auto_submit: true, - min: 0 %> + min: 0, + disabled: @entry.linked?, + disable_currency: @entry.linked? %> <% end %> <% end %> diff --git a/app/views/transactions/_header.html.erb b/app/views/transactions/_header.html.erb index 565892d5..6c7b1615 100644 --- a/app/views/transactions/_header.html.erb +++ b/app/views/transactions/_header.html.erb @@ -15,6 +15,12 @@ <% if entry.transaction.transfer? %> <%= icon "arrow-left-right", class: "mt-1" %> <% end %> + + <% if entry.linked? %> + + <%= icon("refresh-ccw", size: "sm") %> + + <% end %> diff --git a/app/views/transactions/show.html.erb b/app/views/transactions/show.html.erb index 507afa29..d2adc414 100644 --- a/app/views/transactions/show.html.erb +++ b/app/views/transactions/show.html.erb @@ -18,6 +18,7 @@ <%= f.date_field :date, label: t(".date_label"), max: Date.current, + disabled: @entry.linked?, "data-auto-submit-form-target": "auto" %> <% unless @entry.transaction.transfer? %> @@ -25,13 +26,15 @@ <%= f.select :nature, [["Expense", "outflow"], ["Income", "inflow"]], { container_class: "w-1/3", label: t(".nature"), selected: @entry.amount.negative? ? "inflow" : "outflow" }, - { data: { "auto-submit-form-target": "auto" } } %> + { data: { "auto-submit-form-target": "auto" }, disabled: @entry.linked? } %> <%= f.money_field :amount, label: t(".amount"), container_class: "w-2/3", auto_submit: true, min: 0, - value: @entry.amount.abs %> + value: @entry.amount.abs, + disabled: @entry.linked?, + disable_currency: @entry.linked? %> <%= f.fields_for :entryable do |ef| %>