<commit_before>class OrderItemsController < ApplicationController
  rescue_from OrderItem::NotEnoughInventory, with: :not_enough_inventory

  def new
    @order_item = OrderItem.new
    @last_delivery = current_user.last_delivery
    @last_order = current_user.last_ordered_product

    @bookings = current_user.bookings.all
    @bookings_today = current_user.bookings.where('created_at >= ?', Time.zone.now.beginning_of_day)
  end

  def create
    OrderItem.transaction do
      @order_item = OrderItem.new order_item_params
      @order = @order_item.build_order
      @order.build_booking user: current_user

      if @order_item.save
        redirect_to :new_order_item, notice: "Consumo sagt, #{@order_item.delivery.product.name} gebucht. Hai!"
      else
        redirect_to :new_order_item, alert: 'Consumo sagt, nix gut.'
      end
    end
  end

  private

  def order_item_params
    params.require(:order_item).permit(:delivery_id, :amount)
  end

  private

  def not_enough_inventory
    redirect_to :new_order_item, alert: 'Consumo sagt, wir nix genug Zeug da!'
  end
end<commit_msg>fixes stats not beeing calculated for region #33<commit_after>class OrderItemsController < ApplicationController
  rescue_from OrderItem::NotEnoughInventory, with: :not_enough_inventory

  def new
    @order_item = OrderItem.new
    @last_delivery = current_user.last_delivery
    @last_order = current_user.last_ordered_product

    @bookings = current_user.bookings.by_realm(current_user.current_realm_id)
    @bookings_today = @bookings.where('created_at >= ?', Time.zone.now.beginning_of_day)
  end

  def create
    OrderItem.transaction do
      @order_item = OrderItem.new order_item_params
      @order = @order_item.build_order
      @order.build_booking user: current_user

      if @order_item.save
        redirect_to :new_order_item, notice: "Consumo sagt, #{@order_item.delivery.product.name} gebucht. Hai!"
      else
        redirect_to :new_order_item, alert: 'Consumo sagt, nix gut.'
      end
    end
  end

  private

  def order_item_params
    params.require(:order_item).permit(:delivery_id, :amount)
  end

  private

  def not_enough_inventory
    redirect_to :new_order_item, alert: 'Consumo sagt, wir nix genug Zeug da!'
  end
end
{'fraction_non_alphanumeric': 0.08070953436807095, 'fraction_numerical': 0.0008869179600886918, 'mean_word_length': 3.9473684210526314, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3507461', 'n_tokens_mistral': 760, 'n_tokens_neox': 744, 'n_words': 156}