<commit_before>class Invoice < ActiveRecord::Base
  include ::BaseInvoice

  belongs_to :consolidated_tax
  belongs_to :customer
  has_many :slips
  belongs_to :invoice_project

  attr_accessible :date, :number, :paid, :payment_date, :consolidated_tax_id, :slip_ids

  # Returns the invoices with consolidated taxes with at least one tax with withholding flag at true
  scope :withholding_taxes, -> { joins(consolidated_tax: :taxes).where(taxes: { withholding: true }).uniq }

  validates :date, presence: true
  validates :customer, presence: true
  validates :consolidated_tax, presence: true
  validates :slips, presence: true
  validate :customer_must_exist
  validate :consolidated_tax_must_exist

  def self.next_option_name
    'NEXT_INVOICE_NUMBER'
  end

  # Get the sum of the slips' rates
  def rate
    sum = 0
    self.slips.each { |slip| sum += slip.rate }
    sum
  end

  # Returns the withholding rate of an invoice
  def withholding_rate
    rate = 0
    sum = self.rate
    compounds = []
    self.consolidated_tax.taxes.each do |tax|
      partial = sum * tax.rate / 100
      if tax.compound<commit_msg>Fixes error with Postgres<commit_after>class Invoice < ActiveRecord::Base
  include ::BaseInvoice

  belongs_to :consolidated_tax
  belongs_to :customer
  has_many :slips
  belongs_to :invoice_project

  attr_accessible :date, :number, :paid, :payment_date, :consolidated_tax_id, :slip_ids

  # Returns the invoices with consolidated taxes with at least one tax with withholding flag at true
  scope :withholding_taxes, -> { joins(consolidated_tax: :taxes).where(taxes: { withholding: true }) }

  validates :date, presence: true
  validates :customer, presence: true
  validates :consolidated_tax, presence: true
  validates :slips, presence: true
  validate :customer_must_exist
  validate :consolidated_tax_must_exist

  def self.next_option_name
    'NEXT_INVOICE_NUMBER'
  end

  # Get the sum of the slips' rates
  def rate
    sum = 0
    self.slips.each { |slip| sum += slip.rate }
    sum
  end

  # Returns the withholding rate of an invoice
  def withholding_rate
    rate = 0
    sum = self.rate
    compounds = []
    self.consolidated_tax.taxes.each do |tax|
      partial = sum * tax.rate / 100
      if tax.compound
{'fraction_non_alphanumeric': 0.07760532150776053, 'fraction_numerical': 0.004434589800443459, 'mean_word_length': 3.8308351177730193, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2318629', 'n_tokens_mistral': 768, 'n_tokens_neox': 705, 'n_words': 215}