<commit_before>module Comable
  class OrderItem < ActiveRecord::Base
    include Comable::SkuItem
    include Comable::SkuChoice
    include Comable::Liquidable
    include Comable::OrderItem::Csvable

    belongs_to :variant, class_name: Comable::Variant.name, autosave: true
    belongs_to :order, class_name: Comable::Order.name, inverse_of: :order_items

    validates :quantity, numericality: { greater_than: 0 }
    validates :sku, length: { maximum: 255 }
    validate :valid_stock_quantity

    liquid_methods :name, :name_with_sku, :code, :quantity, :price, :subtotal_price

    delegate :product, to: :variant
    delegate :image_url, to: :product
    delegate :guest_token, to: :order
    delegate :completed?, to: :order, allow_nil: true

    before_validation :copy_attributes, unless: :completed?

    def complete
      # Nothing to do
    end

    def unstock
      decrement_stock
    end

    def restock
      increment_stock
    end

    # TODO: カート投入時との差額表示
    def copy_attributes
      self.attributes = current_attributes
    end

    # 時価を取得
    def current_price
      variant.price
    end

    # 時価小計を取得
    def current_subtotal_price
      current_price * quantity
    end

    # 売価小計を取得
    def subtotal_price
      price * quantity
    end

    def unstocked?
      stock_with_clean_quantity do |stock|
        stock.unstocked?(quantity: quantity)
      end
    end

    def sku_h_item_name
      product.option_types.first.try(:name)
    end
<commit_msg>Fix the failed test cases for OrdersController<commit_after>module Comable
  class OrderItem < ActiveRecord::Base
    include Comable::SkuItem
    include Comable::SkuChoice
    include Comable::Liquidable
    include Comable::OrderItem::Csvable

    belongs_to :variant, class_name: Comable::Variant.name, autosave: true
    belongs_to :order, class_name: Comable::Order.name, inverse_of: :order_items

    validates :quantity, numericality: { greater_than: 0 }
    validates :sku, length: { maximum: 255 }
    validate :valid_stock_quantity

    liquid_methods :name, :name_with_sku, :code, :quantity, :price, :subtotal_price

    delegate :product, to: :variant
    delegate :image_url, to: :product
    delegate :guest_token, to: :order
    delegate :completed?, to: :order, allow_nil: true

    before_validation :copy_attributes, unless: :completed?

    def complete
      # Nothing to do
    end

    def unstock
      decrement_stock
    end

    def restock
      increment_stock
    end

    # TODO: カート投入時との差額表示
    def copy_attributes
      self.attributes = current_attributes
    end

    # 時価を取得
    def current_price
      variant.price
    end

    # 時価小計を取得
    def current_subtotal_price
      current_price * quantity
    end

    # 売価小計を取得
    def subtotal_price
      price * quantity
    end

    def unstocked?
      !variant.can_supply? quantity
    end

    def sku_h_item_name
      product.option_types.first.try(:name)
    end

{'fraction_non_alphanumeric': 0.07067618076792388, 'fraction_numerical': 0.0027183146449201497, 'mean_word_length': 3.03840877914952, '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': '4538128', 'n_tokens_mistral': 997, 'n_tokens_neox': 951, 'n_words': 236}