mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 05:09:38 +02:00
* Flatten Holding model * Flatten balance model * Entries domain renames * Fix valuations reference * Fix trades stream * Fix brakeman warnings * Fix tests * Replace existing entryable type references in DB
47 lines
1 KiB
Ruby
47 lines
1 KiB
Ruby
module EntryableResource
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
include StreamExtensions, ActionView::RecordIdentifier
|
|
|
|
before_action :set_entry, only: %i[show update destroy]
|
|
end
|
|
|
|
def show
|
|
end
|
|
|
|
def new
|
|
account = Current.family.accounts.find_by(id: params[:account_id])
|
|
|
|
@entry = Current.family.entries.new(
|
|
account: account,
|
|
currency: account ? account.currency : Current.family.currency,
|
|
entryable: entryable
|
|
)
|
|
end
|
|
|
|
def create
|
|
raise NotImplementedError, "Entryable resources must implement #create"
|
|
end
|
|
|
|
def update
|
|
raise NotImplementedError, "Entryable resources must implement #update"
|
|
end
|
|
|
|
def destroy
|
|
account = @entry.account
|
|
@entry.destroy!
|
|
@entry.sync_account_later
|
|
|
|
redirect_back_or_to account_path(account), notice: t("account.entries.destroy.success")
|
|
end
|
|
|
|
private
|
|
def entryable
|
|
controller_name.classify.constantize.new
|
|
end
|
|
|
|
def set_entry
|
|
@entry = Current.family.entries.find(params[:id])
|
|
end
|
|
end
|