mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-14 04:04:23 +00:00
Add OrderCycle#distributed_variants
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user