client_management/app/models/contract_purchase.rb

21 lines
474 B
Ruby

class ContractPurchase
include Mongoid::Document
include Mongoid::Timestamps
field :total_amount, type: Integer, :default => 0
belongs_to :request_contract
has_many :purchase_receipts
def total_amount_recieved
self.purchase_receipts.sum(:amount_received)
end
def total_adjusted_amount
self.purchase_receipts.sum(:adjustable_amount)
end
def cleared?
self.total_amount == (self.total_amount_recieved + self.total_adjusted_amount)
end
end