mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 03:54:08 +00:00
Fix [1018]: Add Date field when entering Account Balance (#1068)
* Add new Date field when creating a new Account * Fix german translation * Update app/controllers/concerns/accountable_resource.rb Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Michel Roegl-Brunner <73236783+michelroegl-brunner@users.noreply.github.com> * Add missing opening_balance:date to update_params * Change label text --------- Signed-off-by: Michel Roegl-Brunner <73236783+michelroegl-brunner@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
0f78f54f90
commit
f8d3678a40
@@ -34,7 +34,15 @@ module AccountableResource
|
||||
end
|
||||
|
||||
def create
|
||||
@account = Current.family.accounts.create_and_sync(account_params.except(:return_to))
|
||||
opening_balance_date = begin
|
||||
account_params[:opening_balance_date].presence&.to_date
|
||||
rescue Date::Error
|
||||
nil
|
||||
end || (Time.zone.today - 2.years)
|
||||
@account = Current.family.accounts.create_and_sync(
|
||||
account_params.except(:return_to, :opening_balance_date),
|
||||
opening_balance_date: opening_balance_date
|
||||
)
|
||||
@account.lock_saved_attributes!
|
||||
|
||||
redirect_to account_params[:return_to].presence || @account, notice: t("accounts.create.success", type: accountable_type.name.underscore.humanize)
|
||||
@@ -52,7 +60,7 @@ module AccountableResource
|
||||
end
|
||||
|
||||
# Update remaining account attributes
|
||||
update_params = account_params.except(:return_to, :balance, :currency)
|
||||
update_params = account_params.except(:return_to, :balance, :currency, :opening_balance_date)
|
||||
unless @account.update(update_params)
|
||||
@error_message = @account.errors.full_messages.join(", ")
|
||||
render :edit, status: :unprocessable_entity
|
||||
@@ -85,6 +93,7 @@ module AccountableResource
|
||||
def account_params
|
||||
params.require(:account).permit(
|
||||
:name, :balance, :subtype, :currency, :accountable_type, :return_to,
|
||||
:opening_balance_date,
|
||||
:institution_name, :institution_domain, :notes,
|
||||
accountable_attributes: self.class.permitted_accountable_attributes
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user