app/models/esa/ruleset.rb in event_sourced_accounting-0.1.0 vs app/models/esa/ruleset.rb in event_sourced_accounting-0.1.1
- old
+ new
@@ -1,11 +1,13 @@
+require 'esa/traits/extendable'
+
module ESA
# The Ruleset class contains the business logic and rules of accounting.
#
# @author Lenno Nagel
class Ruleset < ActiveRecord::Base
- include Traits::Extendable
+ include ESA::Traits::Extendable
attr_accessible :name, :type, :chart
attr_readonly :name, :type, :chart
belongs_to :chart
@@ -69,14 +71,10 @@
def flags_needing_adjustment(accountable)
natures = accountable.esa_flags.pluck(:nature).uniq.map{|nature| nature.to_sym}
most_recent_flags = natures.map do |nature|
- accountable.esa_flags.joins(:event).readonly(false).
- where("esa_events.nature = 'adjustment' OR esa_flags.transition != 0").
- where(nature: nature).
- order('time DESC, created_at DESC').
- first
+ accountable.esa_flags.transitioning.most_recent(nature)
end.compact
most_recent_flags.select(&:is_set?).reject do |flag|
attributes = flag_transactions_as_attributes(flag)