<commit_before>class LineItem < ActiveRecord::Base
  # Aspects
  include ApplicationHelper

  # Ordering
  default_scope order(:position)

  # Associations
  belongs_to :invoice, :touch => true, :inverse_of => :line_items
  belongs_to :debit_account, :class_name => 'Account'
  belongs_to :credit_account, :class_name => 'Account'

  # Validations
  validates :invoice, :presence => true
  validates :times, :presence => true, :numericality => true, :unless => :is_a_saldo_line_item?
  validates :price, :presence => true, :numericality => true
  validates :title, :presence => true
  validates :credit_account, :presence => true
  validates :debit_account, :presence => true

  # String
  def to_s
    "%s: %s (%s %s %s)" % [self.title, self.accounted_amount, self.times, self.quantity, self.price]
  end

  # Copying
  def copy
    new_item = dup
    new_item.include_in_saldo_list = include_in_saldo_list
    new_item
  end

  # Scopes
  scope :saldo_items, where(:quantity => 'saldo_of')
  scope :non_saldo_items, where("quantity != 'saldo_of'")<commit_msg>fix(line-items): only validate account relations if no saldo line item<commit_after>class LineItem < ActiveRecord::Base
  # Aspects
  include ApplicationHelper

  # Ordering
  default_scope order(:position)

  # Associations
  belongs_to :invoice, :touch => true, :inverse_of => :line_items
  belongs_to :debit_account, :class_name => 'Account'
  belongs_to :credit_account, :class_name => 'Account'

  # Validations
  validates :invoice, :presence => true
  validates :times, :presence => true, :numericality => true, :unless => :is_a_saldo_line_item?
  validates :price, :presence => true, :numericality => true
  validates :title, :presence => true
  validates :credit_account, :presence => true, :unless => :is_a_saldo_line_item?
  validates :debit_account, :presence => true, :unless => :is_a_saldo_line_item?

  # String
  def to_s
    "%s: %s (%s %s %s)" % [self.title, self.accounted_amount, self.times, self.quantity, self.price]
  end

  # Copying
  def copy
    new_item = dup
    new_item.include_in_saldo_list = include_in_saldo_list
    new_item
  end

  # Scopes
  scope :saldo_items, where(:quantity => 'saldo_of')
  scope :non_saldo_items, where("quantity != 'saldo_of'")
{'fraction_non_alphanumeric': 0.12094264117385504, 'fraction_numerical': 0.0, 'mean_word_length': 4.7251908396946565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '1168545', 'n_tokens_mistral': 804, 'n_tokens_neox': 783, 'n_words': 186}