Add method to close all invoices with an invoice direct

When the charge_members_manually option is active there is no need for an
explicit balancing step. This new function allows to close_direct all
orders which have an assigned invoice, which is usually indication enough
to find orders which can be closed finally.
This commit is contained in:
Patrick Gansterer 2020-02-28 12:17:27 +01:00
parent 226d2dda74
commit ecb4a8a4ba
6 changed files with 31 additions and 5 deletions

View file

@ -29,16 +29,16 @@ class Finance::BalancingController < Finance::BaseController
render layout: false if request.xhr?
end
def new_on_order_article_create # See publish/subscribe design pattern in /doc.
@order_article = OrderArticle.find(params[:order_article_id])
render :layout => false
end
def new_on_order_article_update # See publish/subscribe design pattern in /doc.
@order_article = OrderArticle.find(params[:order_article_id])
render :layout => false
end
@ -85,4 +85,17 @@ class Finance::BalancingController < Finance::BaseController
redirect_to finance_order_index_url, alert: t('finance.balancing.close_direct.alert', message: error.message)
end
def close_all_direct_with_invoice
count = 0
Order.transaction do
Order.finished_not_closed.with_invoice.each do |order|
order.close_direct! current_user
count += 1
end
end
redirect_to finance_order_index_url, notice: t('finance.balancing.close_all_direct_with_invoice.notice', count: count)
rescue => error
redirect_to finance_order_index_url, alert: t('errors.general_msg', msg: error.message)
end
end