<commit_before>module Spree
  module Admin
    class RecurringListOrdersController < Spree::Admin::BaseController

      def create
        @recurring_order = Spree::RecurringOrder.find(params[:recurring_order_id])
        if base_list.nil?
          fail_with_message('Recurring order does not have a base list')
        elsif base_list.user.has_incomplete_order_booked?
          fail_with_message('User has already an existing incomplete order with delivery date set')
        else
          @recurring_order.save
          new_order = @recurring_order.create_order_from_base_list
          if new_order.valid?
            if @recurring_order.complete_after_create
              new_order.auto_complete
              flash[:warning] = 'Order created but auto completing it failed' unless new_order.complete?
            else
              @recurring_order.complete_after_create = false
            end
            redirect_to(edit_admin_order_url(new_order.number))
          else
            fail_with_message("#{new_order.errors.full_messages.first}")
          end
        end
      end

      private

      def fail_with_message(message)
        flash[:error] = "Order creation failed - #{message}" 
        redirect_to(admin_recurring_order_url(@recurring_order.number))
      end

      def base_list
        @recurring_order.base_list
      end

    end
  end
end<commit_msg>not completing recurring order after creation - will do it in the service<commit_after>module Spree
  module Admin
    class RecurringListOrdersController < Spree::Admin::BaseController

      def create
        @recurring_order = Spree::RecurringOrder.find(params[:recurring_order_id])
        if base_list.nil?
          fail_with_message('Recurring order does not have a base list')
        elsif base_list.user.has_incomplete_order_booked?
          fail_with_message('User has already an existing incomplete order with delivery date set')
        else
          @recurring_order.save
          new_order = @recurring_order.create_order_from_base_list
          if new_order.valid?
            redirect_to(edit_admin_order_url(new_order.number))
          else
            fail_with_message("#{new_order.errors.full_messages.first}")
          end
        end
      end

      private

      def fail_with_message(message)
        flash[:error] = "Order creation failed - #{message}" 
        redirect_to(admin_recurring_order_url(@recurring_order.number))
      end

      def base_list
        @recurring_order.base_list
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.06336088154269973, 'fraction_numerical': 0.0, 'mean_word_length': 2.5652173913043477, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6078522', 'n_tokens_mistral': 729, 'n_tokens_neox': 715, 'n_words': 153}