Add tax treatment classification for investment accounts with international support (#693)

* Add tax treatment support for accounts, investments, and cryptos

* Replace hardcoded region labels with I18n translations

* Add I18n support for subtype labels with fallback to hardcoded values

* fixed schema

---------

Co-authored-by: luckyPipewrench <luckypipewrench@proton.me>
This commit is contained in:
LPW
2026-01-18 11:29:02 -05:00
committed by GitHub
parent 6ec03e93f4
commit 64dc5c2fb8
14 changed files with 488 additions and 23 deletions

View File

@@ -31,11 +31,17 @@ module Accountable
end
# Given a subtype, look up the label for this accountable type
# Uses i18n with fallback to hardcoded SUBTYPES values
def subtype_label_for(subtype, format: :short)
return nil if subtype.nil?
label_type = format == :long ? :long : :short
self::SUBTYPES[subtype]&.fetch(label_type, nil)
fallback = self::SUBTYPES.dig(subtype, label_type)
I18n.t(
"#{name.underscore.pluralize}.subtypes.#{subtype}.#{label_type}",
default: fallback
)
end
# Convenience method for getting the short label

View File

@@ -0,0 +1,26 @@
module TaxTreatable
extend ActiveSupport::Concern
# Delegates tax treatment to the accountable (Investment or Crypto)
# Returns nil for account types that don't support tax treatment
def tax_treatment
return nil unless accountable.respond_to?(:tax_treatment)
accountable.tax_treatment&.to_sym
end
# Returns the i18n label for the tax treatment
def tax_treatment_label
return nil unless tax_treatment
I18n.t("accounts.tax_treatments.#{tax_treatment}")
end
# Returns true if the account has tax advantages (deferred, exempt, or advantaged)
def tax_advantaged?
tax_treatment.in?(%i[tax_deferred tax_exempt tax_advantaged])
end
# Returns true if gains in this account are taxable
def taxable?
tax_treatment == :taxable || tax_treatment.nil?
end
end