mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-08 15:05:22 +02:00
Update properties controller to use new creational and update balance methods
This commit is contained in:
parent
d459ebdad8
commit
25f0c78c47
17 changed files with 500 additions and 144 deletions
|
@ -1,7 +1,7 @@
|
|||
module Family::AccountCreatable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def create_property_account!(name:, current_value:, purchase_price: nil, purchase_date: nil, currency: nil)
|
||||
def create_property_account!(name:, current_value:, purchase_price: nil, purchase_date: nil, currency: nil, draft: false)
|
||||
create_manual_account!(
|
||||
name: name,
|
||||
balance: current_value,
|
||||
|
@ -9,11 +9,12 @@ module Family::AccountCreatable
|
|||
accountable_type: Property,
|
||||
opening_balance: purchase_price,
|
||||
opening_date: purchase_date,
|
||||
currency: currency
|
||||
currency: currency,
|
||||
draft: draft
|
||||
)
|
||||
end
|
||||
|
||||
def create_vehicle_account!(name:, current_value:, purchase_price: nil, purchase_date: nil, currency: nil)
|
||||
def create_vehicle_account!(name:, current_value:, purchase_price: nil, purchase_date: nil, currency: nil, draft: false)
|
||||
create_manual_account!(
|
||||
name: name,
|
||||
balance: current_value,
|
||||
|
@ -21,23 +22,25 @@ module Family::AccountCreatable
|
|||
accountable_type: Vehicle,
|
||||
opening_balance: purchase_price,
|
||||
opening_date: purchase_date,
|
||||
currency: currency
|
||||
currency: currency,
|
||||
draft: draft
|
||||
)
|
||||
end
|
||||
|
||||
def create_depository_account!(name:, current_balance:, opening_date: nil, currency: nil)
|
||||
def create_depository_account!(name:, current_balance:, opening_date: nil, currency: nil, draft: false)
|
||||
create_manual_account!(
|
||||
name: name,
|
||||
balance: current_balance,
|
||||
cash_balance: current_balance,
|
||||
accountable_type: Depository,
|
||||
opening_date: opening_date,
|
||||
currency: currency
|
||||
currency: currency,
|
||||
draft: draft
|
||||
)
|
||||
end
|
||||
|
||||
# Investment account values are built up by adding holdings / trades, not by initializing a "balance"
|
||||
def create_investment_account!(name:, currency: nil)
|
||||
def create_investment_account!(name:, currency: nil, draft: false)
|
||||
create_manual_account!(
|
||||
name: name,
|
||||
balance: 0,
|
||||
|
@ -45,11 +48,12 @@ module Family::AccountCreatable
|
|||
accountable_type: Investment,
|
||||
opening_balance: 0, # Investment accounts start empty
|
||||
opening_cash_balance: 0,
|
||||
currency: currency
|
||||
currency: currency,
|
||||
draft: draft
|
||||
)
|
||||
end
|
||||
|
||||
def create_other_asset_account!(name:, current_value:, purchase_price: nil, purchase_date: nil, currency: nil)
|
||||
def create_other_asset_account!(name:, current_value:, purchase_price: nil, purchase_date: nil, currency: nil, draft: false)
|
||||
create_manual_account!(
|
||||
name: name,
|
||||
balance: current_value,
|
||||
|
@ -57,11 +61,12 @@ module Family::AccountCreatable
|
|||
accountable_type: OtherAsset,
|
||||
opening_balance: purchase_price,
|
||||
opening_date: purchase_date,
|
||||
currency: currency
|
||||
currency: currency,
|
||||
draft: draft
|
||||
)
|
||||
end
|
||||
|
||||
def create_other_liability_account!(name:, current_debt:, original_debt: nil, origination_date: nil, currency: nil)
|
||||
def create_other_liability_account!(name:, current_debt:, original_debt: nil, origination_date: nil, currency: nil, draft: false)
|
||||
create_manual_account!(
|
||||
name: name,
|
||||
balance: current_debt,
|
||||
|
@ -69,12 +74,13 @@ module Family::AccountCreatable
|
|||
accountable_type: OtherLiability,
|
||||
opening_balance: original_debt,
|
||||
opening_date: origination_date,
|
||||
currency: currency
|
||||
currency: currency,
|
||||
draft: draft
|
||||
)
|
||||
end
|
||||
|
||||
# For now, crypto accounts are very simple; we just track overall value
|
||||
def create_crypto_account!(name:, current_value:, currency: nil)
|
||||
def create_crypto_account!(name:, current_value:, currency: nil, draft: false)
|
||||
create_manual_account!(
|
||||
name: name,
|
||||
balance: current_value,
|
||||
|
@ -82,11 +88,12 @@ module Family::AccountCreatable
|
|||
accountable_type: Crypto,
|
||||
opening_balance: current_value,
|
||||
opening_cash_balance: current_value,
|
||||
currency: currency
|
||||
currency: currency,
|
||||
draft: draft
|
||||
)
|
||||
end
|
||||
|
||||
def create_credit_card_account!(name:, current_debt:, opening_date: nil, currency: nil)
|
||||
def create_credit_card_account!(name:, current_debt:, opening_date: nil, currency: nil, draft: false)
|
||||
create_manual_account!(
|
||||
name: name,
|
||||
balance: current_debt,
|
||||
|
@ -94,11 +101,12 @@ module Family::AccountCreatable
|
|||
accountable_type: CreditCard,
|
||||
opening_balance: 0, # Credit cards typically start with no debt
|
||||
opening_date: opening_date,
|
||||
currency: currency
|
||||
currency: currency,
|
||||
draft: draft
|
||||
)
|
||||
end
|
||||
|
||||
def create_loan_account!(name:, current_principal:, original_principal: nil, origination_date: nil, currency: nil)
|
||||
def create_loan_account!(name:, current_principal:, original_principal: nil, origination_date: nil, currency: nil, draft: false)
|
||||
create_manual_account!(
|
||||
name: name,
|
||||
balance: current_principal,
|
||||
|
@ -106,7 +114,8 @@ module Family::AccountCreatable
|
|||
accountable_type: Loan,
|
||||
opening_balance: original_principal,
|
||||
opening_date: origination_date,
|
||||
currency: currency
|
||||
currency: currency,
|
||||
draft: draft
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -128,14 +137,15 @@ module Family::AccountCreatable
|
|||
|
||||
private
|
||||
|
||||
def create_manual_account!(name:, balance:, cash_balance:, accountable_type:, opening_balance: nil, opening_cash_balance: nil, opening_date: nil, currency: nil)
|
||||
def create_manual_account!(name:, balance:, cash_balance:, accountable_type:, opening_balance: nil, opening_cash_balance: nil, opening_date: nil, currency: nil, draft: false)
|
||||
Family.transaction do
|
||||
account = accounts.create!(
|
||||
name: name,
|
||||
balance: balance,
|
||||
cash_balance: cash_balance,
|
||||
currency: currency.presence || self.currency,
|
||||
accountable: accountable_type.new
|
||||
accountable: accountable_type.new,
|
||||
status: draft ? "draft" : "active"
|
||||
)
|
||||
|
||||
account.set_or_update_opening_balance!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue