Skip to content

Commit

Permalink
selecting the latest subscription if there are multiple subscriptions of
Browse files Browse the repository at this point in the history
the same service
  • Loading branch information
ij committed Mar 16, 2019
1 parent f368274 commit 984b393
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/sf/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,11 @@ def self.active_inc_parts(service_name)
private

def subscriptions
Sf.client.query("select Service__r.Id, Service__r.Name, Service_Start_Date__c, Service_End_Date__c from Service_Institution__c where Supporting_Institution__c = \'#{self.Id}\'")
end

def subscription_names
subscriptions.map{|s| s.Service__r.Name}
# sorting by Service_Start_Date__c in case of multiple subscriptions of the same service
Sf.client.query("select Service__r.Id, Service__r.Name, Service_Start_Date__c, Service_End_Date__c from Service_Institution__c where Supporting_Institution__c = \'#{self.Id}\' ORDER BY Service_Start_Date__c")
end

# The latest subscription is included only in case of the multiple subscriptions of the same service.
def start_dates_by_subscription
start_dates = {}
subscriptions.each {|s| start_dates[s.Service__r.Name] = s.Service_Start_Date__c}
Expand Down

0 comments on commit 984b393

Please sign in to comment.