From 45add7512b000120a0e740f987ed0397b15296a1 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Mon, 16 Dec 2024 12:52:11 -0500 Subject: [PATCH] Handle nil name for entries (#1550) * Handle nil name for entries * Fix tests --- .erb-lint.yml => .erb_lint.yml | 0 app/models/account/data_enricher.rb | 4 ++- app/models/account/transaction.rb | 2 +- app/models/account/valuation.rb | 4 +++ .../transactions/_transaction.html.erb | 6 ++--- .../account/valuations/_valuation.html.erb | 4 +-- app/views/shared/_circle_logo.html.erb | 2 +- bin/erblint | 27 ------------------- .../locales/views/account/valuations/en.yml | 2 -- config/locales/views/settings/hostings/en.yml | 3 ++- 10 files changed, 16 insertions(+), 38 deletions(-) rename .erb-lint.yml => .erb_lint.yml (100%) delete mode 100755 bin/erblint diff --git a/.erb-lint.yml b/.erb_lint.yml similarity index 100% rename from .erb-lint.yml rename to .erb_lint.yml diff --git a/app/models/account/data_enricher.rb b/app/models/account/data_enricher.rb index 4beb0b9294c..e0615cc134b 100644 --- a/app/models/account/data_enricher.rb +++ b/app/models/account/data_enricher.rb @@ -23,6 +23,8 @@ def enrich_transactions candidates.each do |entry| if entry.enriched_at.nil? || entry.entryable.merchant_id.nil? || entry.entryable.category_id.nil? begin + next unless entry.name.present? + info = self.class.synth_provider.enrich_transaction(entry.name).info next unless info.present? @@ -48,7 +50,7 @@ def enrich_transactions category.save! if category.present? entry.update!( enriched_at: Time.current, - name: entry.enriched_at.nil? ? info.name : entry.name, + name: entry.enriched_at.nil? && info.name ? info.name : entry.name, entryable_attributes: entryable_attributes ) end diff --git a/app/models/account/transaction.rb b/app/models/account/transaction.rb index 91f24f70f98..fbf2aa9e54c 100644 --- a/app/models/account/transaction.rb +++ b/app/models/account/transaction.rb @@ -49,7 +49,7 @@ def searchable_keys end def name - entry.name || "(no description)" + entry.name || (entry.amount.positive? ? "Expense" : "Income") end def eod_balance diff --git a/app/models/account/valuation.rb b/app/models/account/valuation.rb index 93ebf5ffb1f..5a4d1b8f66c 100644 --- a/app/models/account/valuation.rb +++ b/app/models/account/valuation.rb @@ -10,4 +10,8 @@ def requires_search?(_params) false end end + + def name + "Balance update" + end end diff --git a/app/views/account/transactions/_transaction.html.erb b/app/views/account/transactions/_transaction.html.erb index 9a37a958095..d63ddf8b6f4 100644 --- a/app/views/account/transactions/_transaction.html.erb +++ b/app/views/account/transactions/_transaction.html.erb @@ -14,14 +14,14 @@ <% if entry.account_transaction.merchant&.icon_url %> <%= image_tag entry.account_transaction.merchant.icon_url, class: "w-6 h-6 rounded-full" %> <% else %> - <%= render "shared/circle_logo", name: entry.name, size: "sm" %> + <%= render "shared/circle_logo", name: transaction.name, size: "sm" %> <% end %>
<% if entry.new_record? %> - <%= content_tag :p, entry.name %> + <%= content_tag :p, transaction.name %> <% else %> - <%= link_to entry.name, + <%= link_to transaction.name, entry.transfer.present? ? account_transfer_path(entry.transfer) : account_entry_path(entry), data: { turbo_frame: "drawer", turbo_prefetch: false }, class: "hover:underline hover:text-gray-800" %> diff --git a/app/views/account/valuations/_valuation.html.erb b/app/views/account/valuations/_valuation.html.erb index fc4c05d012b..0761fd17b03 100644 --- a/app/views/account/valuations/_valuation.html.erb +++ b/app/views/account/valuations/_valuation.html.erb @@ -18,9 +18,9 @@
<% if entry.new_record? %> - <%= content_tag :p, entry.name %> + <%= content_tag :p, entry.entryable.name %> <% else %> - <%= link_to entry.name || t(".balance_update"), + <%= link_to entry.entryable.name, account_entry_path(entry), data: { turbo_frame: "drawer", turbo_prefetch: false }, class: "hover:underline hover:text-gray-800" %> diff --git a/app/views/shared/_circle_logo.html.erb b/app/views/shared/_circle_logo.html.erb index 17f1948af80..e8dd7c1fff6 100644 --- a/app/views/shared/_circle_logo.html.erb +++ b/app/views/shared/_circle_logo.html.erb @@ -9,5 +9,5 @@ <%= tag.div style: mixed_hex_styles(hex), class: [size_classes[size], "flex shrink-0 items-center justify-center rounded-full"] do %> - <%= tag.span name[0].upcase, class: ["font-medium", size == "sm" ? "text-xs" : "text-sm"] %> + <%= tag.span (name.presence&.first || "T").upcase, class: ["font-medium", size == "sm" ? "text-xs" : "text-sm"] %> <% end %> diff --git a/bin/erblint b/bin/erblint deleted file mode 100755 index 63d662cffa9..00000000000 --- a/bin/erblint +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'erblint' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) - -bundle_binstub = File.expand_path("bundle", __dir__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("erb_lint", "erblint") diff --git a/config/locales/views/account/valuations/en.yml b/config/locales/views/account/valuations/en.yml index ba8637c6ac2..c157b6d62b4 100644 --- a/config/locales/views/account/valuations/en.yml +++ b/config/locales/views/account/valuations/en.yml @@ -2,8 +2,6 @@ en: account: valuations: - valuation: - balance_update: Balance update form: amount: Amount submit: Add balance update diff --git a/config/locales/views/settings/hostings/en.yml b/config/locales/views/settings/hostings/en.yml index dcd65f060fb..b3f04fc982a 100644 --- a/config/locales/views/settings/hostings/en.yml +++ b/config/locales/views/settings/hostings/en.yml @@ -3,7 +3,8 @@ en: settings: hostings: data_enrichment_settings: - description: Enable data enrichment for your account transactions. This will incur additional Synth credits. + description: Enable data enrichment for your account transactions. This will + incur additional Synth credits. title: Data Enrichment invite_code_settings: description: Every new user that joins your instance of Maybe can only do