我想在客户付款后跟踪发票余额,我该如何实现?
我有嵌套资源
resources :invoices do
resources :payments
end
发票模型如下:
class Invoice < ActiveRecord::Base
belongs_to :customer, :inverse_of => :invoices
attr_accessible :due_date, :invoice_date, :reading_ids, :customer_id, :customer, :status, :amount, :balance
has_many :invoice_items, :dependent => :destroy
has_many :payments, :dependent => :destroy
end
支付模式如下:
class Payment < ActiveRecord::Base
attr_accessible :amount, :method, :payment_date, :reference_no, :invoice_id
belongs_to :invoice
end
每当客户付款时,我想从余额中减去付款并为该发票存储新余额。这将成为发票的新余额。
我怎样才能做到这一点?