mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
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:
@@ -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
|
||||
|
||||
26
app/models/concerns/tax_treatable.rb
Normal file
26
app/models/concerns/tax_treatable.rb
Normal 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
|
||||
Reference in New Issue
Block a user