Skip to content

Commit

Permalink
IN-392 find pricebook2 and save into the order
Browse files Browse the repository at this point in the history
  • Loading branch information
reinaldob committed Oct 22, 2014
1 parent e0065cf commit 47a0940
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
14 changes: 10 additions & 4 deletions lib/SF_services/order.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module SFService
class Order < Base
def initialize(config)
super("Order__c", config)
super("Opportunity", config)
end

def is_present?(id)
Expand All @@ -18,11 +18,17 @@ def find_account_id_by_email(email)
results.any? ? results.first['Account__c'] : nil
end

def find_price_book_by_id(price_book_id)
results = salesforce.query("select Id from PriceBook2 where Name = '#{price_book_id}'")
results.any? ? results.first['Id'] : nil
end

def upsert!(order_attr = {})
email = order_attr.fetch 'AccountId'
account_id = find_account_id_by_email(email)
account_id = find_account_id_by_email(order_attr.fetch 'AccountId')
price_book_id = find_price_book_by_id(order_attr.fetch 'Pricebook2Id')

order_attr = order_attr.merge( { 'AccountId' => account_id } ) if account_id.present?
order_attr = order_attr.merge( { 'AccountId' => account_id } ) if account_id.present?
order_attr = order_attr.merge( { 'Pricebook2Id' => price_book_id } ) if price_book_id.present?

order_id = is_present?(order_attr.fetch 'Name')
order_id.present? ? update!(order_attr.merge({ Id: order_id })) : create!(order_attr)
Expand Down
8 changes: 2 additions & 6 deletions lib/integrations/builders/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ def build
'CloseDate' => object['placed_on'],
'HasOpportunityLineItem' => true,
'Name' => object['id'],
'Pricebook2Id' => get_pricebook2,
'StageName' => object['status'],
'Pricebook2Id' => object['price_book_id'],
'StageName' => object.has_key?('stage_name') ? object['stage_name'] : object['status'],
'CurrencyIsoCode' => object['currency']
}
end

def get_pricebook2

end
end
end
end

0 comments on commit 47a0940

Please sign in to comment.