<commit_before>class Order < ActiveRecord::Base
  belongs_to :seller
  belongs_to :customer
  belongs_to :delivery_address
  belongs_to :transport
  belongs_to :company
  has_many :order_items

  def discount
    100.0 * (1.0-self.price / self.order_items.inject(0.0){|sum,item| sum+item.price})
  end

end
<commit_msg>Bugfix for price for new objects<commit_after>class Order < ActiveRecord::Base
  belongs_to :seller
  belongs_to :customer
  belongs_to :delivery_address
  belongs_to :transport
  belongs_to :company
  has_many :order_items

  def discount
    if self.price.nil?
      0
    else
      100.0 * (1.0-self.price / self.order_items.inject(0.0){|sum,item| sum+item.price})
    end
  end

end

{'fraction_non_alphanumeric': 0.09476661951909476, 'fraction_numerical': 0.024045261669024046, 'mean_word_length': 3.816326530612245, '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': '6569231', 'n_tokens_mistral': 256, 'n_tokens_neox': 258, 'n_words': 56}