<commit_before>require 'spree/core/validators/email'
require 'spree/order/checkout'

module Spree
  class Order < ActiveRecord::Base
    include Checkout

    checkout_flow do
      go_to_state :address
      go_to_state :delivery
      go_to_state :payment, if: ->(order) {
        order.update_totals
        order.payment_required?
      }
      go_to_state :confirm, if: ->(order) { order.confirmation_required? }
      go_to_state :complete
      remove_transition from: :delivery, to: :confirm
    end

    token_resource

    attr_accessible :line_items, :bill_address_attributes, :ship_address_attributes,
                    :payments_attributes, :ship_address, :bill_address, :currency,
                    :line_items_attributes, :number, :email, :use_billing, 
                    :special_instructions, :shipments_attributes, :coupon_code

    attr_reader :coupon_code

    if Spree.user_class
      belongs_to :user, class_name: Spree.user_class.to_s
    else
      belongs_to :user
    end

    belongs_to :bill_address, foreign_key: :bill_address_id, class_name: 'Spree::Address'
    alias_attribute :billing_address, :bill_address

    belongs_to :ship_address, foreign_key: :ship_address_id, class_name: 'Spree::Address'
    alias_attribute :shipping_address, :ship_address

    has_many :state_changes, as: :stateful
    has_many :line_items, dependent: :destroy, order: 'created_at ASC'
    has_many :payments, dependent: :destroy

    has_many :shipments, dependent: :destroy do
      def states
        pluck(:state).uniq
      end
    end

    has_many :return_authorizations, dependent: :destroy
    has_many :adjustments, as: :adjustable, dependent: :destroy, order: 'created_at ASC'

    accepts_nested_attributes_for :line_items
    accepts_nested_attributes_for :bill_address
    accepts_nested_attributes_for :ship_address
    accepts_nested_attributes_for :payments
    accepts_nested_attributes_for :shipments

    # Needs to happen before save_permalink is called
    before_validation :set_currency<commit_msg>add table_name to fix "order created_at" exception error<commit_after>require 'spree/core/validators/email'
require 'spree/order/checkout'

module Spree
  class Order < ActiveRecord::Base
    include Checkout

    checkout_flow do
      go_to_state :address
      go_to_state :delivery
      go_to_state :payment, if: ->(order) {
        order.update_totals
        order.payment_required?
      }
      go_to_state :confirm, if: ->(order) { order.confirmation_required? }
      go_to_state :complete
      remove_transition from: :delivery, to: :confirm
    end

    token_resource

    attr_accessible :line_items, :bill_address_attributes, :ship_address_attributes,
                    :payments_attributes, :ship_address, :bill_address, :currency,
                    :line_items_attributes, :number, :email, :use_billing, 
                    :special_instructions, :shipments_attributes, :coupon_code

    attr_reader :coupon_code

    if Spree.user_class
      belongs_to :user, class_name: Spree.user_class.to_s
    else
      belongs_to :user
    end

    belongs_to :bill_address, foreign_key: :bill_address_id, class_name: 'Spree::Address'
    alias_attribute :billing_address, :bill_address

    belongs_to :ship_address, foreign_key: :ship_address_id, class_name: 'Spree::Address'
    alias_attribute :shipping_address, :ship_address

    has_many :state_changes, as: :stateful
    has_many :line_items, dependent: :destroy, order: "#{Spree::LineItem.table_name}.created_at ASC"
    has_many :payments, dependent: :destroy, :class_name => "Spree::Payment"

    has_many :shipments, dependent: :destroy do
      def states
        pluck(:state).uniq
      end
    end

    has_many :return_authorizations, dependent: :destroy
    has_many :adjustments, as: :adjustable, dependent: :destroy, order: "#{Spree::Adjustment.table_name}.created_at ASC"

    accepts_nested_attributes_for :line_items
    accepts_nested_attributes_for :bill_address
    accepts_nested_attributes_for :ship_address
    accepts_nested_attributes_for :payments
    accepts_nested_attributes_for :shipments

    # Needs to happen before save_permalink is called
    before_validation :set_currency
{'fraction_non_alphanumeric': 0.078125, 'fraction_numerical': 0.0, 'mean_word_length': 3.806598407281001, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '4714150', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1297, 'n_words': 286}