1-account.rb
class Account < ActiveRecord::Base
belongs_to :transaction
end
class Supplier < Account
end
class Expense < Account
end
2- transaction.rb
class Transaction < ActiveRecord::Base
has_many :accounts
accepts_nested_attributes_for :accounts
end
3迁移架构
create_table "accounts", :force => true do |t|
t.string "name"
t.decimal "debit"
t.decimal "credit"
t.decimal "balance"
t.string "type"
t.integer "transaction_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "transactions", :force => true do |t|
t.string "name"
t.decimal "amount"
t.date "date"
t.string "document"
t.datetime "created_at"
t.datetime "updated_at"
end
end
问题1 : 在视图中达到供应商和费用的最佳方法是什么(见下图)?
问题2 :
如何实现一种在expense_debit
和supplier_credit
中自动记录交易金额的方法,反之亦然? (View screenshot)
答案 0 :(得分:1)
我建议另类设置。首先,您的交易不会记录&#34;来自&#34;帐户,&#34;到&#34;帐户。这对于以后知道很重要。
我认识到可能有多个帐户来自......但是借记卡与信用卡应该按照每笔交易记录,而不是仅仅记入帐户中的一个大块,否则以后会很难例如,列出日期A和日期B之间帐户值的变化(对于纳税申报表或季度销售报告或其他任何内容很重要)。
我不知道命名,但也许交易有多个帐户转移,转移是&#34; transaction_id,account_id,金额,方向&#34; (方向为借方/贷方)。