balancing controller unreachable code #30

Open
opened 2022-11-28 11:16:15 +01:00 by philipp · 0 comments
Owner

app/controllers/finance/balancing_controller.rb

  def new
    @order = Order.find(params[:order_id])
    flash.now.alert = t('finance.balancing.new.alert') if @order.closed?
    @comments = @order.comments

    @articles = @order.order_articles.ordered_or_member.includes(:article, :article_price,
                                                                 group_order_articles: { group_order: :ordergroup })

    sort_param = params['sort'] || 'name'
    @articles = case sort_param
                when 'name' then
                  @articles.order('articles.name ASC')
                when 'name_reverse' then
                  @articles.order('articles.name DESC')
                when 'order_number' then
                  @articles.order('articles.order_number ASC')
                when 'order_number_reverse' then
                  @articles.order('articles.order_number DESC')
                else
                  @articles # TODO: We will never get here
                end

    render layout: false if request.xhr?
  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) # TODO: this can't be reached
  end
end
app/controllers/finance/balancing_controller.rb ```ruby def new @order = Order.find(params[:order_id]) flash.now.alert = t('finance.balancing.new.alert') if @order.closed? @comments = @order.comments @articles = @order.order_articles.ordered_or_member.includes(:article, :article_price, group_order_articles: { group_order: :ordergroup }) sort_param = params['sort'] || 'name' @articles = case sort_param when 'name' then @articles.order('articles.name ASC') when 'name_reverse' then @articles.order('articles.name DESC') when 'order_number' then @articles.order('articles.order_number ASC') when 'order_number_reverse' then @articles.order('articles.order_number DESC') else @articles # TODO: We will never get here end render layout: false if request.xhr? end ``` ```ruby 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) # TODO: this can't be reached end end ```
philipp added the
refactoring
label 2022-11-28 11:16:15 +01:00
philipp added this to the Kanban project 2023-01-17 12:03:53 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Foodsoft/foodsoft#30
No description provided.