class Credit < ActiveRecord::Base belongs_to :customer belongs_to :pointsale belongs_to :sale has_many :credit_payments has_many :cash_registers_moves, through: :credit_payments enum status: [:active, :cancelled, :expired, :liquidated] scope :debtors, -> { where("rest > 0").group(:customer_id).sum(:rest) } scope :activos, -> { where(status: [0, 2]) } end