2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR. If not, see <http://www.gnu.org/licenses/>.
16 class PositionRevision < ActiveRecord::Base
17 include Smr::Extensions::DateTimeWrapper
19 self.inheritance_column = :none
20 belongs_to :Order, :foreign_key=>'id_order'
21 belongs_to :Position, :foreign_key=>'id_position'
22 has_one :Stock, :through => :Position
23 has_one :Portfolio, :through => :Position
26 # types of revisions supported
27 # NOTE: do NOT change the relations! just ADD new numbers!
29 :shares=>0, :order_booking=>1, :cash_booking=>2, :dividend_booking=>3,
30 :redemption_booking=>4, :salary_booking=>5
34 validates :id_order, :id_position, numericality: { greater_than: 0 }
37 # Returns human readable String describing :type. Lookup may be given as
38 # symbol, as string or as numerical index.
39 def PositionRevision.describe_type(lookup)
41 :shares => 'Share Deposit / Discharge',
42 :order_booking => 'Money Equivalent of Order',
43 :cash_booking => 'Cash Deposit / Withdrawal',
44 :dividend_booking => 'Dividend / Interest',
45 :redemption_booking => 'Redemption',
46 :salary_booking => 'Salary',
49 if lookup.is_a?(Numeric) then
50 lookup = self.types.key(lookup) || ''
52 descriptions[lookup.to_sym]
56 # Describes #type of the instance object.
58 PositionRevision.describe_type(type)