Add option to create a financial_link when creating financial_transaction

If multiple financial transaction belong to a bank transaction, it
is sometimes easier to create them as a collection and add the bank
transaction instead of adding all financial transaction to a link
created via a bank transaction.
This commit is contained in:
Patrick Gansterer 2019-10-30 22:27:18 +01:00
parent ef613300e0
commit 260ef90f6b
4 changed files with 28 additions and 11 deletions

View file

@ -56,6 +56,11 @@ class Finance::FinancialTransactionsController < ApplicationController
def create_collection def create_collection
raise I18n.t('finance.financial_transactions.controller.create_collection.error_note_required') if params[:note].blank? raise I18n.t('finance.financial_transactions.controller.create_collection.error_note_required') if params[:note].blank?
type = FinancialTransactionType.find_by_id(params[:type_id]) type = FinancialTransactionType.find_by_id(params[:type_id])
financial_link = nil
ActiveRecord::Base.transaction do
financial_link = FinancialLink.new if params[:create_financial_link]
params[:financial_transactions].each do |trans| params[:financial_transactions].each do |trans|
# ignore empty amount fields ... # ignore empty amount fields ...
unless trans[:amount].blank? unless trans[:amount].blank?
@ -66,10 +71,15 @@ class Finance::FinancialTransactionsController < ApplicationController
note += " (#{amount})" note += " (#{amount})"
amount -= ordergroup.financial_transaction_class_balance(type.financial_transaction_class) amount -= ordergroup.financial_transaction_class_balance(type.financial_transaction_class)
end end
ordergroup.add_financial_transaction!(amount, note, @current_user, type) ordergroup.add_financial_transaction!(amount, note, @current_user, type, financial_link)
end end
end end
redirect_to finance_ordergroups_url, notice: I18n.t('finance.financial_transactions.controller.create_collection.notice')
financial_link.try(&:save!)
end
url = financial_link ? finance_link_url(financial_link.id) : finance_ordergroups_url
redirect_to url, notice: I18n.t('finance.financial_transactions.controller.create_collection.notice')
rescue => error rescue => error
flash.now[:alert] = error.message flash.now[:alert] = error.message
render action: :new_collection render action: :new_collection

View file

@ -56,6 +56,11 @@
%p %p
= link_to t('.new_ordergroup'), '#', 'data-add-transaction' => true, class: 'btn' = link_to t('.new_ordergroup'), '#', 'data-add-transaction' => true, class: 'btn'
= link_to t('.add_all_ordergroups'), '#', 'data-add-all-ordergroups' => true, class: 'btn' = link_to t('.add_all_ordergroups'), '#', 'data-add-all-ordergroups' => true, class: 'btn'
- if BankAccount.any?
%p
%label
= check_box_tag :create_financial_link, true, params[:create_financial_link]
= t('.create_financial_link')
.form-actions .form-actions
= submit_tag t('.save'), class: 'btn btn-primary' = submit_tag t('.save'), class: 'btn btn-primary'
= link_to t('ui.or_cancel'), finance_ordergroups_path = link_to t('ui.or_cancel'), finance_ordergroups_path

View file

@ -838,6 +838,7 @@ de:
title: Neue Transaktion title: Neue Transaktion
new_collection: new_collection:
add_all_ordergroups: Alle Bestellgruppen hinzufügen add_all_ordergroups: Alle Bestellgruppen hinzufügen
create_financial_link: Erstelle einen gemeinsamen Finanzlink für die neuen Transaktionen.
new_ordergroup: Weitere Bestellgruppe hinzufügen new_ordergroup: Weitere Bestellgruppe hinzufügen
save: Transaktionen speichern save: Transaktionen speichern
set_balance: Setze den Kontostand der Bestellgrupppe auf den eingegebenen Betrag. set_balance: Setze den Kontostand der Bestellgrupppe auf den eingegebenen Betrag.

View file

@ -863,6 +863,7 @@ en:
title: New transaction title: New transaction
new_collection: new_collection:
add_all_ordergroups: Add all ordergroups add_all_ordergroups: Add all ordergroups
create_financial_link: Create a common financial link for the new transactions.
new_ordergroup: Add new ordergroup new_ordergroup: Add new ordergroup
save: Save transaction save: Save transaction
set_balance: Set the balance of the ordergroup to the entered amount. set_balance: Set the balance of the ordergroup to the entered amount.