Pipedrive: manager can refuse a deal
This commit is contained in:
parent
8d7c639f8f
commit
d0431a28f2
5 changed files with 48 additions and 0 deletions
|
@ -23,12 +23,25 @@ module Manager
|
|||
end
|
||||
end
|
||||
|
||||
def refuse_administrateur
|
||||
PipedriveRefusesDealsJob.perform_later(
|
||||
refuse_administrateur_params[:person_id],
|
||||
PipedriveService::PIPEDRIVE_CAMILLE_ID
|
||||
)
|
||||
flash.notice = "La demande va être refusée"
|
||||
redirect_to manager_demandes_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_administrateur_params
|
||||
params.permit(:email, :person_id, :stage_id)
|
||||
end
|
||||
|
||||
def refuse_administrateur_params
|
||||
params.permit(:person_id)
|
||||
end
|
||||
|
||||
def pending_demandes
|
||||
already_approved_emails = Administrateur
|
||||
.where(email: demandes.map { |d| d[:email] })
|
||||
|
|
5
app/jobs/pipedrive_refuses_deals_job.rb
Normal file
5
app/jobs/pipedrive_refuses_deals_job.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class PipedriveRefusesDealsJob < ApplicationJob
|
||||
def perform(person_id, owner_id)
|
||||
PipedriveService.refuse_deals_from_person(person_id, owner_id)
|
||||
end
|
||||
end
|
|
@ -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('/')
|
||||
|
||||
|
|
|
@ -48,6 +48,12 @@
|
|||
<%= submit_tag 'Créer' %>
|
||||
<% end -%>
|
||||
</td>
|
||||
<td class="cell-data cell-data--string" style="text-align: center;">
|
||||
<%= button_to('Refuser',
|
||||
manager_demandes_refuse_administrateur_path,
|
||||
params: { person_id: demande[:person_id] },
|
||||
style: 'background-color: #FFFFFF; color: #293f54; border: 1px solid #dfe0e1') %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
|
@ -12,6 +12,7 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :demandes, only: [:index]
|
||||
post 'demandes/create_administrateur'
|
||||
post 'demandes/refuse_administrateur'
|
||||
|
||||
authenticate :administration do
|
||||
match "/delayed_job" => DelayedJobWeb, :anchor => false, :via => [:get, :post]
|
||||
|
|
Loading…
Reference in a new issue