<commit_before># encoding: utf-8
# author: <NAME>
# email: <EMAIL>
class Income < Account

  # module for setters and getters
  extend SettersGetters

  include Models::IncomeExpense
  ########################################
  # Callbacks
  before_save :set_client_and_incomes_status

  ########################################
  # Relationships
  belongs_to :contact
  belongs_to :project

  has_one :transaction, foreign_key: :account_id, autosave: true

  has_many :income_details, foreign_key: :account_id, dependent: :destroy, order: 'id asc'
  accepts_nested_attributes_for :income_details, allow_destroy: true,
    reject_if: proc {|det| det.fetch(:item_id).blank? }

  has_many :payments, class_name: 'AccountLedger', foreign_key: :account_id, conditions: {operation: 'payin'}
  has_many :payments_devolutions, class_name: 'AccountLedger', foreign_key: :account_id, conditions: {operation: ['payin', 'devin']}
  has_many :interests, class_name: 'AccountLedger', foreign_key: :account_id, conditions: {operation: 'intin'}

  has_many :transaction_histories, foreign_key: :account_id

  STATES = %w(draft approved paid)
  ########################################
  # Validations
  validates_presence_of :date, :contact, :contact_id
  validates :state, presence: true, inclusion: {in: STATES}

  ########################################
  # Scopes
  scope :discount, joins(:transaction).where(transaction: {discounted: true})
  scope :approved, -> { where(state: 'approved') }
  scope :active,   -> { where(state: ['approved', 'paid']) }
  scope :contact, lampda {|cid| where(contact_id: cid) }
  scope :to_pay_contact, lambda {|cid| contact.where(amount.gt 0) }
  scope :pendent_except, lambda {|iid| active.where{ (id.not_eq iid) & (amount.not_eq 0) } }
  scope :pendent_contact_except, lambda {|cid, iid| contact(cid).pendent_except(iid) }

  ########################################
  # Delegations
  delegate *create_accessors(*Transaction.transaction_columns), to: :transaction
  delegate :discounted?, :delivered?, :devolution?, :total_was,
    :creator, :approver, :nuller, to: :transaction
  delegate :attributes, to: :transaction, prefix: true
  delegate :currency, :name, prefix: :org, to: OrganisationSession, allow_nil: true

  # Define boolean methods for states
  STATES.each do |_state|
    define_method :"is_#{_state}?" do
      _state == state<commit_msg>Ruby 1.9<commit_after># encoding: utf-8
# author: <NAME>
# email: <EMAIL>
class Income < Account

  # module for setters and getters
  extend SettersGetters

  include Models::IncomeExpense
  ########################################
  # Callbacks
  before_save :set_client_and_incomes_status

  ########################################
  # Relationships
  belongs_to :contact
  belongs_to :project

  has_one :transaction, foreign_key: :account_id, autosave: true

  has_many :income_details, foreign_key: :account_id, dependent: :destroy, order: 'id asc'
  accepts_nested_attributes_for :income_details, allow_destroy: true,
    reject_if: proc {|det| det.fetch(:item_id).blank? }

  has_many :payments, class_name: 'AccountLedger', foreign_key: :account_id, conditions: {operation: 'payin'}
  has_many :payments_devolutions, class_name: 'AccountLedger', foreign_key: :account_id, conditions: {operation: ['payin', 'devin']}
  has_many :interests, class_name: 'AccountLedger', foreign_key: :account_id, conditions: {operation: 'intin'}

  has_many :transaction_histories, foreign_key: :account_id

  STATES = %w(draft approved paid)
  ########################################
  # Validations
  validates_presence_of :date, :contact, :contact_id
  validates :state, presence: true, inclusion: {in: STATES}

  ########################################
  # Scopes
  scope :discount, joins(:transaction).where(transaction: {discounted: true})
  scope :approved, -> { where(state: 'approved') }
  scope :active,   -> { where(state: ['approved', 'paid']) }
  scope :contact, lambda {|cid| where(contact_id: cid) }
  scope :to_pay_contact, lambda {|cid| contact.where(amount.gt 0) }
  scope :pendent_except, lambda {|iid| active.where{ (id.not_eq iid) & (amount.not_eq 0) } }
  scope :pendent_contact_except, lambda {|cid, iid| contact(cid).pendent_except(iid) }

  ########################################
  # Delegations
  delegate *create_accessors(*Transaction.transaction_columns), to: :transaction
  delegate :discounted?, :delivered?, :devolution?, :total_was,
    :creator, :approver, :nuller, to: :transaction
  delegate :attributes, to: :transaction, prefix: true
  delegate :currency, :name, prefix: :org, to: OrganisationSession, allow_nil: true

  # Define boolean methods for states
  STATES.each do |_state|
    define_method :"is_#{_state}?" do
      _state == state
{'fraction_non_alphanumeric': 0.19831756046267088, 'fraction_numerical': 0.0016824395373291271, 'mean_word_length': 6.066864784546805, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '1637157', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1476, 'n_words': 366}