mirror of
https://github.com/we-promise/sure.git
synced 2026-07-13 13:25:22 +00:00
PlaidAccount::TypeMappable maps the Plaid loan subtypes "home equity",
"line of credit", and "business" to home_equity, line_of_credit, and
business — but Loan::SUBTYPES never defined them. Linking any such
account (e.g. a HELOC reported by the institution as loan/"line of
credit") makes the item's sync fail with:
Validation failed: Accountable subtype is not included in the list
and, because Link itself succeeded, the failure is silent in the UI
(same UX gap as #1792).
Add the three subtypes to Loan::SUBTYPES, and add a regression test
asserting every subtype emitted by TYPE_MAPPING is valid for its
accountable so the mapper and models can't drift apart again.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
50 lines
1.4 KiB
Ruby
50 lines
1.4 KiB
Ruby
class Loan < ApplicationRecord
|
|
include Accountable
|
|
|
|
SUBTYPES = {
|
|
"mortgage" => { short: "Mortgage", long: "Mortgage" },
|
|
"student" => { short: "Student Loan", long: "Student Loan" },
|
|
"auto" => { short: "Auto Loan", long: "Auto Loan" },
|
|
"home_equity" => { short: "Home Equity", long: "Home Equity Loan" },
|
|
"line_of_credit" => { short: "Line of Credit", long: "Line of Credit" },
|
|
"business" => { short: "Business Loan", long: "Business Loan" },
|
|
"other" => { short: "Other Loan", long: "Other Loan" }
|
|
}.freeze
|
|
|
|
validates :subtype, inclusion: { in: SUBTYPES.keys }, allow_blank: true
|
|
|
|
def monthly_payment
|
|
return nil if term_months.nil? || interest_rate.nil? || rate_type.nil? || rate_type != "fixed"
|
|
return Money.new(0, account.currency) if account.loan.original_balance.amount.zero? || term_months.zero?
|
|
|
|
annual_rate = interest_rate / 100.0
|
|
monthly_rate = annual_rate / 12.0
|
|
|
|
if monthly_rate.zero?
|
|
payment = account.loan.original_balance.amount / term_months
|
|
else
|
|
payment = (account.loan.original_balance.amount * monthly_rate * (1 + monthly_rate)**term_months) / ((1 + monthly_rate)**term_months - 1)
|
|
end
|
|
|
|
Money.new(payment.round, account.currency)
|
|
end
|
|
|
|
def original_balance
|
|
Money.new(account.first_valuation_amount, account.currency)
|
|
end
|
|
|
|
class << self
|
|
def color
|
|
"#D444F1"
|
|
end
|
|
|
|
def icon
|
|
"hand-coins"
|
|
end
|
|
|
|
def classification
|
|
"liability"
|
|
end
|
|
end
|
|
end
|