Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loan start date #1612

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

tonyvince
Copy link
Contributor

close #1605

@zachgoll
Copy link
Collaborator

@tonyvince I think to solve this one, we'll need to take a slightly different approach. Adding a start_date to an Account conflicts with our existing model that relies solely on Account::Valuation and Account::Transaction entries to calculate the historical balance of an account.

A possible approach here would be to include a origination_date and origination_loan_balance field in the initial form the user fills out and then use that information to create an Account::Valuation representing the "starting loan amount".

Currently, for all accounts we're calling create_and_sync which generates 2 valuations by default:

def create_and_sync(attributes)
attributes[:accountable_attributes] ||= {} # Ensure accountable is created, even if empty
account = new(attributes.merge(cash_balance: attributes[:balance]))
transaction do
# Create 2 valuations for new accounts to establish a value history for users to see
account.entries.build(
name: "Current Balance",
date: Date.current,
amount: account.balance,
currency: account.currency,
entryable: Account::Valuation.new
)
account.entries.build(
name: "Initial Balance",
date: 1.day.ago.to_date,
amount: 0,
currency: account.currency,
entryable: Account::Valuation.new
)
account.save!
end
account.sync_later
account
end
end

For loan accounts, we likely want to "specialize" this behavior so that instead of blindly creating a valuation of 0 a day ago, we create a valuation on the origination_date with an amount equal to origination_loan_balance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Loan account type does not have a method to set a start date.
2 participants