<commit_before>Spree::LineItem.class_eval do
  attr_accessible :max_quantity

  # -- Scopes
  scope :managed_by, lambda { |user|
    if user.has_spree_role?('admin')
      scoped
    else
      # Find line items that are from orders distributed by the user or supplied by the user
      joins(:variant => :product).
      joins(:order).
      where('spree_orders.distributor_id IN (?) OR spree_products.supplier_id IN (?)', user.enterprises, user.enterprises).
      select('spree_line_items.*')
    end
  }

  scope :supplied_by, lambda { |enterprise|
    joins(:product).
    where('spree_products.supplier_id = ?', enterprise)
  }
  scope :supplied_by_any, lambda { |enterprises|
    joins(:product).
    where('spree_products.supplier_id IN (?)', enterprises)
  }

  def price_with_adjustments
    # EnterpriseFee#create_locked_adjustment applies adjustments on line items to their parent order,
    # so line_item.adjustments returns an empty array
    (price + order.adjustments.where(source_id: id).sum(&:amount) / quantity).round(2)
  end
<commit_msg>Line items with a quantity of zero return price_with_adjustments of 0.0<commit_after>Spree::LineItem.class_eval do
  attr_accessible :max_quantity

  # -- Scopes
  scope :managed_by, lambda { |user|
    if user.has_spree_role?('admin')
      scoped
    else
      # Find line items that are from orders distributed by the user or supplied by the user
      joins(:variant => :product).
      joins(:order).
      where('spree_orders.distributor_id IN (?) OR spree_products.supplier_id IN (?)', user.enterprises, user.enterprises).
      select('spree_line_items.*')
    end
  }

  scope :supplied_by, lambda { |enterprise|
    joins(:product).
    where('spree_products.supplier_id = ?', enterprise)
  }
  scope :supplied_by_any, lambda { |enterprises|
    joins(:product).
    where('spree_products.supplier_id IN (?)', enterprises)
  }

  def price_with_adjustments
    # EnterpriseFee#create_locked_adjustment applies adjustments on line items to their parent order,
    # so line_item.adjustments returns an empty array
    return 0 if quantity == 0
    (price + order.adjustments.where(source_id: id).sum(&:amount) / quantity).round(2)
  end

{'fraction_non_alphanumeric': 0.10652765185856754, 'fraction_numerical': 0.0027198549410698096, 'mean_word_length': 3.7978260869565217, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2478548', 'n_tokens_mistral': 707, 'n_tokens_neox': 687, 'n_words': 173}