mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 03:55:20 +02:00
Remove existing data enrichment for clean slate
This commit is contained in:
parent
6644afe147
commit
8effdcb2d3
10 changed files with 7 additions and 98 deletions
|
@ -116,7 +116,7 @@ The most important type of sync is the account sync. It is orchestrated by the
|
|||
- Auto-matches transfer records for the account
|
||||
- Calculates daily [balance.rb](mdc:app/models/account/balance.rb) records for the account from `account.start_date` to `Date.current` using [base_calculator.rb](mdc:app/models/account/balance/base_calculator.rb)
|
||||
- Balances are dependent on the calculation of [holding.rb](mdc:app/models/account/holding.rb), which uses [base_calculator.rb](mdc:app/models/account/holding/base_calculator.rb)
|
||||
- Enriches transaction data if enabled by user
|
||||
- Updates data according to rules created by user
|
||||
|
||||
An account sync happens every time an [entry.rb](mdc:app/models/account/entry.rb) is updated.
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ class UsersController < ApplicationController
|
|||
def user_params
|
||||
params.require(:user).permit(
|
||||
:first_name, :last_name, :email, :profile_image, :redirect_to, :delete_profile_image, :onboarded_at, :show_sidebar, :default_period, :show_ai_sidebar, :ai_enabled,
|
||||
family_attributes: [ :name, :currency, :country, :locale, :date_format, :timezone, :id, :data_enrichment_enabled ]
|
||||
family_attributes: [ :name, :currency, :country, :locale, :date_format, :timezone, :id ]
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
class EnrichTransactionBatchJob < ApplicationJob
|
||||
queue_as :low_priority
|
||||
|
||||
def perform(account, batch_size = 100, offset = 0)
|
||||
account.enrich_transaction_batch(batch_size, offset)
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
class Account < ApplicationRecord
|
||||
include Syncable, Monetizable, Chartable, Enrichable, Linkable, Convertible
|
||||
include Syncable, Monetizable, Chartable, Linkable, Convertible
|
||||
|
||||
validates :name, :balance, :currency, presence: true
|
||||
|
||||
|
@ -78,11 +78,6 @@ class Account < ApplicationRecord
|
|||
|
||||
Rails.logger.info("Processing balances (#{linked? ? 'reverse' : 'forward'})")
|
||||
sync_balances
|
||||
|
||||
if enrichable?
|
||||
Rails.logger.info("Enriching transaction data")
|
||||
enrich_data
|
||||
end
|
||||
end
|
||||
|
||||
def post_sync
|
||||
|
|
|
@ -152,7 +152,7 @@ class Demo::Generator
|
|||
Security::Price.destroy_all
|
||||
end
|
||||
|
||||
def create_family_and_user!(family_name, user_email, data_enrichment_enabled: false, currency: "USD")
|
||||
def create_family_and_user!(family_name, user_email, currency: "USD")
|
||||
base_uuid = "d99e3c6e-d513-4452-8f24-dc263f8528c0"
|
||||
id = Digest::UUID.uuid_v5(base_uuid, family_name)
|
||||
|
||||
|
@ -161,7 +161,6 @@ class Demo::Generator
|
|||
name: family_name,
|
||||
currency: currency,
|
||||
stripe_subscription_status: "active",
|
||||
data_enrichment_enabled: data_enrichment_enabled,
|
||||
locale: "en",
|
||||
country: "US",
|
||||
timezone: "America/New_York",
|
||||
|
|
|
@ -159,38 +159,9 @@ class Provider::Synth < Provider
|
|||
end
|
||||
end
|
||||
|
||||
# ================================
|
||||
# Transactions
|
||||
# ================================
|
||||
|
||||
def enrich_transaction(description, amount: nil, date: nil, city: nil, state: nil, country: nil)
|
||||
with_provider_response do
|
||||
params = {
|
||||
description: description,
|
||||
amount: amount,
|
||||
date: date,
|
||||
city: city,
|
||||
state: state,
|
||||
country: country
|
||||
}.compact
|
||||
|
||||
response = client.get("#{base_url}/enrich", params)
|
||||
|
||||
parsed = JSON.parse(response.body)
|
||||
|
||||
TransactionEnrichmentData.new(
|
||||
name: parsed.dig("merchant"),
|
||||
icon_url: parsed.dig("icon"),
|
||||
category: parsed.dig("category")
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
attr_reader :api_key
|
||||
|
||||
TransactionEnrichmentData = Data.define(:name, :icon_url, :category)
|
||||
|
||||
def base_url
|
||||
ENV["SYNTH_URL"] || "https://api.synthfinance.com"
|
||||
end
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
<%# locals: (user:) %>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="space-y-1">
|
||||
<p class="text-sm"><%= t(".title") %></p>
|
||||
<p class="text-secondary text-sm"><%= t(".description") %></p>
|
||||
<% if self_hosted? %>
|
||||
<p class="text-xs italic text-secondary"><%= t(".self_host_disclaimer") %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= styled_form_with model: user,
|
||||
data: { controller: "auto-submit-form", "auto-submit-form-trigger-event-value": "blur" } do |form| %>
|
||||
<div class="relative inline-block select-none">
|
||||
<%= form.hidden_field :redirect_to, value: "preferences" %>
|
||||
<%= form.fields_for :family do |family_form| %>
|
||||
<%= family_form.check_box :data_enrichment_enabled, class: "sr-only peer", "data-auto-submit-form-target": "auto", "data-autosubmit-trigger-event": "input" %>
|
||||
<%= family_form.label :data_enrichment_enabled, " ".html_safe, class: "switch" %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
|
@ -41,10 +41,6 @@
|
|||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= settings_section title: t(".data"), subtitle: t(".data_subtitle") do %>
|
||||
<%= render "settings/preferences/data_enrichment_settings", user: @user %>
|
||||
<% end %>
|
||||
|
||||
<%= settings_section title: t(".theme_title"), subtitle: t(".theme_subtitle") do %>
|
||||
<div>
|
||||
<%= styled_form_with model: @user, class: "flex justify-between items-center" do |form| %>
|
||||
|
|
|
@ -7,16 +7,9 @@ en:
|
|||
subscription_subtitle: Update your subscription and billing details
|
||||
subscription_title: Manage subscription
|
||||
preferences:
|
||||
data_enrichment_settings:
|
||||
description: Let Maybe auto-categorize, name, and add merchant data to your
|
||||
transactions on each sync. All enrichment is done in English.
|
||||
self_host_disclaimer: This will incur Synth API credits.
|
||||
title: Transaction enrichment (English only)
|
||||
show:
|
||||
country: Country
|
||||
currency: Currency
|
||||
data: Data enrichment
|
||||
data_subtitle: Enable data enrichment for your accounts
|
||||
date_format: Date format
|
||||
general_subtitle: Configure your preferences
|
||||
general_title: General
|
||||
|
|
|
@ -8,6 +8,9 @@ class Provider::SynthTest < ActiveSupport::TestCase
|
|||
@subject = @synth = Provider::Synth.new(ENV["SYNTH_API_KEY"])
|
||||
end
|
||||
|
||||
test "health check" do
|
||||
VCR.use_cassette("synth/health") do
|
||||
assert @synth.healthy?
|
||||
test "health check" do
|
||||
VCR.use_cassette("synth/health") do
|
||||
assert @synth.healthy?
|
||||
|
@ -23,21 +26,4 @@ class Provider::SynthTest < ActiveSupport::TestCase
|
|||
assert usage.plan.present?
|
||||
end
|
||||
end
|
||||
|
||||
test "enriches transaction" do
|
||||
VCR.use_cassette("synth/transaction_enrich") do
|
||||
response = @synth.enrich_transaction(
|
||||
"UBER EATS",
|
||||
amount: 25.50,
|
||||
date: Date.iso8601("2025-03-16"),
|
||||
city: "San Francisco",
|
||||
state: "CA",
|
||||
country: "US"
|
||||
)
|
||||
|
||||
data = response.data
|
||||
assert data.name.present?
|
||||
assert data.category.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue