app/models/account.rb in has_accounts-1.1.3 vs app/models/account.rb in has_accounts-2.0.0
- old
+ new
@@ -14,47 +14,62 @@
# String
def to_s(format = :default)
"%s (%s)" % [title, code]
end
+ # Parent Account
+ # ==============
+ belongs_to :parent, :class_name => Account
+ attr_accessible :parent, :parent_id
+
# Account Type
# ============
belongs_to :account_type
attr_accessible :title, :code, :account_type_id, :account_type
validates_presence_of :account_type
- def is_asset_account?
+ def asset_account?
Account.by_type(['current_assets', 'capital_assets', 'costs']).exists?(self)
end
+ # Deprecated
+ alias_method :is_asset_account?, :asset_account?
- def is_liability_account?
- !is_asset_account?
+ def liability_account?
+ !asset_account?
end
+ # Deprecated
+ alias_method :is_liability_account?, :liability_account?
- def is_balance_account?
+ def balance_account?
Account.by_type(['current_assets', 'capital_assets', 'outside_capital', 'equity_capital']).exists?(self)
end
+ # Deprecated
+ alias_method :is_balance_account?, :balance_account?
- def is_profit_account?
- !is_balance_account?
+ def profit_account?
+ !balance_account?
end
+ # Deprecated
+ alias_method :is_profit_account?, :profit_account?
scope :by_type, lambda {|value| includes(:account_type).where('account_types.name' => value)} do
include AccountScopeExtension
end
# Tagging
# =======
- acts_as_taggable
- attr_accessible :tag_list
+ if defined?(ActsAsTaggableOn) && ActsAsTaggableOn::Tag.table_exists?
+ acts_as_taggable
+ attr_accessible :tag_list
- def self.default_tags
- ['invoice:debit', 'invoice:earnings', 'invoice:credit', 'invoice:costs', 'vat:credit', 'vat:debit']
- end
+ def self.default_tags
+ ['invoice:debit', 'invoice:earnings', 'invoice:credit', 'invoice:costs', 'vat:credit', 'vat:debit']
+ end
- def self.tag_collection
- (default_tags + Account.tag_counts.pluck(:name)).uniq
+ def self.tag_collection
+ (default_tags + Account.tag_counts.pluck(:name)).uniq
+ end
end
# Holder
# ======
belongs_to :holder, :polymorphic => true
@@ -66,14 +81,14 @@
def bookings
Booking.by_account(id)
end
- # Attachments
- # ===========
- has_many :attachments, :as => :object
- accepts_nested_attributes_for :attachments, :reject_if => proc { |attributes| attributes['file'].blank? }
+ # Balances grouped by references which have not 0
+ def unbalanced_references
+ bookings.unbalanced_by_grouped_reference(self.id)
+ end
# Helpers
# =======
def self.overview(value_range = Date.today, format = :default)
Account.all.map{|a| a.to_s(value_range, format)}
@@ -127,10 +142,10 @@
end
def saldo(selector = Date.today, inclusive = true)
credit_amount, debit_amount = turnover(selector, inclusive)
- amount = credit_amount - debit_amount
+ amount = debit_amount - credit_amount
return is_asset_account? ? amount : -amount
end
end