Beispiel #1
0
 def cron_pipedrive_person_exec(self):
     _logger.info('cron_pipedrive_person_exec')
     # params
     pipedrive_domain = str(
         self.env['ir.config_parameter'].sudo().get_param(
             'pipedrive_domain'))
     pipedrive_api_token = str(
         self.env['ir.config_parameter'].sudo().get_param(
             'pipedrive_api_token'))
     # api client
     client = Client(domain=pipedrive_domain)
     client.set_api_token(pipedrive_api_token)
     # get_info
     response = client.persons.get_all_persons()
     if 'success' in response:
         if response['success']:
             for data_item in response['data']:
                 data_item['owner_id'] = data_item['owner_id']['id']
                 # org_id
                 if data_item['org_id'] is not None:
                     if 'id' in data_item['org_id']:
                         data_item['org_id'] = data_item['org_id']['id']
                     else:
                         data_item['org_id'] = None
                 else:
                     data_item['org_id'] = None
                 # action_item
                 self.action_item({
                     'current': data_item,
                     'meta': {
                         'action': 'updated'
                     }
                 })
Beispiel #2
0
    def create_pipedrive_organization(domain: str, api_token: str, **kwargs):
        from pipedrive.client import Client

        client = Client(domain=domain)
        client.set_api_token(api_token)
        payload = {'name': kwargs.get('org_name')}
        return client.organizations.create_organization(payload)
Beispiel #3
0
def add_activiy(how):
    url = 'https://companydomain.pipedrive.com/v1/activities?api_token=' + apiToken
    client = Client(domain=url)
    client.set_api_token(apiToken)
    count = 0
    users = []
    while count < how:
        users.append(get_user(count + 1))

        print(users)
        data = {
            'subject': 'Call to the president',
            'type': 'Call',
            'org_id': get_organization(),  # add Call activity
            'done': 1,  # 0 means than activity is done.
            'person_id': users[count]
        }
        data2 = {
            'subject': 'Call to the minister',
            'type': 'Meeting',  # add meeting activity
            'org_id': get_organization(),
            'done': 1,
            'person_id': users[count]
        }
        count += 1
        client = Client(domain=url)
        client.set_api_token(apiToken)
        response = client.activities.create_activity(data)
        response = client.activities.create_activity(data2)
Beispiel #4
0
    def create_pipedrive_note(domain: str, api_token: str, conversation: str,
                              **kwargs):
        from pipedrive.client import Client

        client = Client(domain=domain)
        client.set_api_token(api_token)
        payload = {'content': conversation, 'lead_id': kwargs.get('lead_id')}
        return client.notes.create_note(payload)
Beispiel #5
0
def create_organization():
    url = 'https://companydomain.pipedrive.com/v1/organizations?api_token=' + apiToken
    client = Client(domain=url)  # autoryzation
    client.set_api_token(apiToken)

    data = {
        "name": getData.orgName,  # name of the organization
    }
    response = client.organizations.create_organization(data)
Beispiel #6
0
    def validate_pipedrive_credentials(domain: str, api_token: str):
        from pipedrive.client import Client
        from pipedrive.exceptions import UnauthorizedError

        try:
            client = Client(domain=domain)
            client.set_api_token(api_token)
            client.leads.get_all_leads()
        except UnauthorizedError as e:
            raise ActionFailure(e)
Beispiel #7
0
def get_organization():
    url = 'https://companydomain.pipedrive.com/v1/organizations?api_token=' + apiToken
    client = Client(domain=url)
    client.set_api_token(apiToken)

    helper = client.organizations.get_all_organizations()
    helper2 = (helper['data'])
    orgID = helper2[0]
    orgID = (orgID['id'])  # ID of company!!!!!!!!!!!!!
    return orgID
Beispiel #8
0
    def create_pipedrive_person(domain: str, api_token: str, **kwargs):
        from pipedrive.client import Client

        client = Client(domain=domain)
        client.set_api_token(api_token)
        email = [kwargs['email']] if kwargs.get('email') else None
        phone = [kwargs['phone']] if kwargs.get('phone') else None
        payload = {
            'name': kwargs.get('name'),
            'org_id': kwargs.get('org_id'),
            'email': email,
            'phone': phone
        }
        return client.persons.create_person(payload)
Beispiel #9
0
 def cron_pipedrive_pipeline_exec(self):
     _logger.info('cron_pipedrive_pipeline_exec')
     # params
     pipedrive_domain = str(
         self.env['ir.config_parameter'].sudo().get_param(
             'pipedrive_domain'))
     pipedrive_api_token = str(
         self.env['ir.config_parameter'].sudo().get_param(
             'pipedrive_api_token'))
     # api client
     client = Client(domain=pipedrive_domain)
     client.set_api_token(pipedrive_api_token)
     # get_info
     response = client.pipelines.get_all_pipelines()
     if 'success' in response:
         if response['success']:
             for data_item in response['data']:
                 self.action_item(data_item)
Beispiel #10
0
    def create_pipedrive_lead(domain: str, api_token: str, title: str,
                              conversation: str, **kwargs):
        from pipedrive.client import Client

        client = Client(domain=domain)
        client.set_api_token(api_token)
        if kwargs.get('org_name'):
            organization = ActionUtility.create_pipedrive_organization(
                domain, api_token, **kwargs)
            kwargs['org_id'] = organization['id']
        person = ActionUtility.create_pipedrive_person(domain, api_token,
                                                       **kwargs)
        payload = {
            'title': title,
            'person_id': person['data']['id'],
            'organization_id': kwargs.get('org_id')
        }
        lead = client.leads.create_lead(payload)
        kwargs['lead_id'] = lead['data']['id']
        ActionUtility.create_pipedrive_note(domain, api_token, conversation,
                                            **kwargs)
Beispiel #11
0
def get_user(howMany):
    url = 'https://api.pipedrive.com/v1/persons?start=0&api_token=' + apiToken
    client = Client(domain=url)
    response = client.set_api_token(apiToken)
    count = 0
    personID = []
    while count < howMany:
        helper = client.persons.get_all_persons()
        helper2 = helper['data']
        personID = helper2[count]
        personID = personID['id']  # ID persons, all persons !!!!!!!!!!!!!
        count += 1

    return personID
Beispiel #12
0
 def cron_pipedrive_activity_exec(self):
     _logger.info('cron_pipedrive_activity_exec')
     # params
     pipedrive_domain = str(
         self.env['ir.config_parameter'].sudo().get_param(
             'pipedrive_domain'))
     pipedrive_api_token = str(
         self.env['ir.config_parameter'].sudo().get_param(
             'pipedrive_api_token'))
     # api client
     client = Client(domain=pipedrive_domain)
     client.set_api_token(pipedrive_api_token)
     # get_info
     response = client.activities.get_all_activities()
     if 'success' in response:
         if response['success']:
             for data_item in response['data']:
                 # keys_need_check
                 keys_need_check = ['owner_id']
                 for key_need_check in keys_need_check:
                     if key_need_check in data_item:
                         if data_item[key_need_check] is not None:
                             if 'id' in data_item[key_need_check]:
                                 data_item[key_need_check] = \
                                     data_item[key_need_check]['id']
                             else:
                                 data_item[key_need_check] = None
                         else:
                             data_item[key_need_check] = None
                 # action_item
                 self.action_item({
                     'current': data_item,
                     'meta': {
                         'action': 'updated'
                     }
                 })
Beispiel #13
0
def add_users(how):
    # url = 'https://' + companyDomain + '.pipedrive.com/v1/persons/' + '?api_token=' + apiToken
    url = 'https://api.pipedrive.com/v1/persons?start=0&api_token=' + apiToken

    client = Client(domain=url)
    response = client.set_api_token(apiToken)
    count = 0
    orgID = get_organization()
    while count < how:
        data = {
            'name': getData.employees[count],  # add person with organization
            'org_id': orgID
        }

        response = client.persons.create_person(data)
        count += 1