管理多模型的Plutus会计系统

时间:2017-12-21 07:30:48

标签: ruby-on-rails accounting

我正在努力建立一个学校管理系统。这里有两个名称空间:学校和教师。我能够为教师维护plutus会计系统。现在我也需要为学校保持相同。以下是我目前的配置:

初​​始化/ plutus.rb

Plutus.config do |config|
  config.enable_tenancy = true
  config.tenant_class = "School"
end

模型/ teacher.rb

has_many :accounts, class_name: "Plutus::Account", foreign_key: "tenant_id"
after_create :create_plutus_accounts
before_destroy :destroy_plutus_accounts
  def create_plutus_accounts
    Plutus::Asset.create(name: "Accounts Receivable", tenant: self)
    Plutus::Asset.create(name: "Cash", tenant: self)
    Plutus::Asset.create(name: "Sales Tax Paid", tenant: self)
    Plutus::Revenue.create(:name => "Sales Revenue", tenant: self)
    Plutus::Expense.create(name: "Workwear", tenant: self)
    Plutus::Expense.create(name: "Travel", tenant: self)
    Plutus::Expense.create(name: "Phone and Internet", tenant: self)
    Plutus::Expense.create(name: "Professional Development", tenant: self)
    Plutus::Expense.create(name: "Professional Literature", tenant: self)
    Plutus::Expense.create(name: "Administration Costs", tenant: self)
    Plutus::Expense.create(name: "Phone and Internet", tenant: self)
    Plutus::Expense.create(name: "Office Supplies", tenant: self)
    Plutus::Expense.create(name: "Maintenance", tenant: self)
    Plutus::Expense.create(name: "Representation", tenant: self)
    Plutus::Expense.create(name: "Other General Costs", tenant: self)
    Plutus::Liability.create(name: "Unearned Revenue", tenant: self)
    Plutus::Liability.create(name: "Sales Tax Payable", tenant: self)
    Plutus::Equity.create(name: "Equity", tenant: self)
  end

  def destroy_plutus_accounts
    Plutus::Account.where(tenant: self).destroy_all
  end

我尝试在学校模型中复制粘贴相同的教师模型代码。之后,当我运行School.first.create_plutus_accounts我面临以下问题时:

ActiveRecord::AssociationTypeMismatch: Teacher(#70257249141660) expected, got School(#70257261264760)

0 个答案:

没有答案