Sha256: 1c9681303cce3c89f41ef739b6bd1ec34e84d2790f69e71597743ac3d31c9d54
Contents?: true
Size: 1.31 KB
Versions: 15
Compression:
Stored size: 1.31 KB
Contents
module Billing class Modifier < ActiveRecord::Base include BillItem belongs_to :bill, inverse_of: :modifiers#, validate: true belongs_to :charge, inverse_of: :modifier monetize :fixed_value_cents scope :global, -> { where(charge_id: nil) } validate :percent_or_value validates_uniqueness_of :charge, scope: :bill_id, allow_nil: true validates_uniqueness_of :bill, scope: :charge_id def percentage percent_ratio.nil? ? "" : "#{(percent_ratio * 100).to_i}%" end def positive? percent_ratio.nil? ? fixed_value_cents > 0 : percent_ratio > 0 end private def percent_or_value errors.add :percent_or_value, I18n.t('errors.messages.blank') if percent_ratio.blank? and fixed_value.zero? errors.add :percent_or_value, I18n.t('errors.messages.present') if percent_ratio.present? and !fixed_value.zero? end class << self def wild_args(*args) case when args.blank? || args.first.kind_of?(Hash) then {}.merge(*args) when args.first.kind_of?(String) then d = args.shift if d.index('%') #TODO parse end else h = { fixed_value: args.shift.to_money } args.any? ? h.merge(*args) : h end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems