Add OrderCycle#distributed_variants

This commit is contained in:
Rohan Mitchell
2013-05-28 14:01:04 +10:00
parent fbac41b060
commit 9ef7da1339
2 changed files with 17 additions and 2 deletions

View File

@@ -5,6 +5,9 @@ class OrderCycle < ActiveRecord::Base
has_many :exchanges, :dependent => :destroy
# TODO: DRY the incoming/outgoing clause used in several cases below
# See Spree::Product definition, scopes variants and variants_including_master
# This will require these accessors to be renamed
attr_accessor :incoming_exchanges, :outgoing_exchanges
validates_presence_of :name, :coordinator_id
@@ -29,6 +32,10 @@ class OrderCycle < ActiveRecord::Base
self.exchanges.map(&:variants).flatten.uniq
end
def distributed_variants
self.exchanges.where(:sender_id => self.coordinator).map(&:variants).flatten.uniq
end
def products
self.variants.map(&:product).uniq
end