add functionality in views and controllers for generation of group order invoices

This commit is contained in:
Viehlieb 2021-12-23 01:51:44 +01:00
parent 817c680c28
commit 50017fefa8
8 changed files with 41 additions and 4 deletions

View file

@ -81,9 +81,21 @@ class Finance::BalancingController < Finance::BaseController
@order = Order.find(params[:id])
@type = FinancialTransactionType.find_by_id(params.permit(:type)[:type])
@order.close!(@current_user, @type)
redirect_to finance_order_index_url, notice: t('finance.balancing.close.notice')
rescue => error
redirect_to new_finance_order_url(order_id: @order.id), alert: t('finance.balancing.close.alert', message: error.message)
note = t('finance.balancing.close.notice')
if @order.closed?
if FoodsoftConfig[:group_order_invoices]&.[](:use) && FoodsoftConfig[:contact]&.[](:tax_number)
@order.group_orders.each do |go|
goi = GroupOrderInvoice.find_or_create_by!(group_order_id: go.id)
if goi.save!
NotifyGroupOrderInvoiceJob.perform_later(goi)
note = t('finance.balancing.close.notice_mail')
end
end
end
end
redirect_to finance_order_index_url, notice: note
rescue => error
redirect_to new_finance_order_url(order_id: @order.id), notice: note, alert: t('finance.balancing.close.alert', message: error.message)
end
# Close the order directly, without automaticly updating ordergroups account balances