Pipedrive: manager can refuse a deal
This commit is contained in:
parent
8d7c639f8f
commit
d0431a28f2
5 changed files with 48 additions and 0 deletions
|
@ -6,12 +6,16 @@ class PipedriveService
|
|||
|
||||
PIPEDRIVE_ALL_NOT_DELETED_DEALS = 'all_not_deleted'
|
||||
|
||||
PIPEDRIVE_LOST_STATUS = "lost"
|
||||
PIPEDRIVE_LOST_REASON = "refusé depuis DS"
|
||||
|
||||
PIPEDRIVE_ADMIN_CENTRAL_STOCK_STAGE_ID = 35
|
||||
PIPEDRIVE_REGIONS_STOCK_STAGE_ID = 24
|
||||
PIPEDRIVE_PREFECTURES_STOCK_STAGE_ID = 20
|
||||
PIPEDRIVE_DEPARTEMENTS_STOCK_STAGE_ID = 30
|
||||
PIPEDRIVE_COMMUNES_STOCK_STAGE_ID = 40
|
||||
PIPEDRIVE_ORGANISMES_STOCK_STAGE_ID = 1
|
||||
PIPEDRIVE_ORGANISMES_REFUSES_STOCK_STAGE_ID = 45
|
||||
|
||||
class << self
|
||||
def accept_deals_from_person(person_id, owner_id, stage_id)
|
||||
|
@ -20,6 +24,12 @@ class PipedriveService
|
|||
update_person_owner(person_id, owner_id)
|
||||
end
|
||||
|
||||
def refuse_deals_from_person(person_id, owner_id)
|
||||
waiting_deal_ids = fetch_waiting_deal_ids(person_id)
|
||||
waiting_deal_ids.each { |deal_id| refuse_deal(deal_id, owner_id) }
|
||||
update_person_owner(person_id, owner_id)
|
||||
end
|
||||
|
||||
def fetch_people_demandes
|
||||
params = {
|
||||
start: 0,
|
||||
|
@ -44,6 +54,19 @@ class PipedriveService
|
|||
|
||||
private
|
||||
|
||||
def refuse_deal(deal_id, owner_id)
|
||||
url = PIPEDRIVE_DEALS_URL + "/#{deal_id}?api_token=#{PIPEDRIVE_TOKEN}"
|
||||
|
||||
params = {
|
||||
user_id: owner_id,
|
||||
stage_id: PIPEDRIVE_ORGANISMES_REFUSES_STOCK_STAGE_ID,
|
||||
status: PIPEDRIVE_LOST_STATUS,
|
||||
lost_reason: PIPEDRIVE_LOST_REASON
|
||||
}
|
||||
|
||||
RestClient.put(url, params.to_json, { content_type: :json })
|
||||
end
|
||||
|
||||
def fetch_waiting_deal_ids(person_id)
|
||||
url = [PIPEDRIVE_PEOPLE_URL, person_id, "deals"].join('/')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue