Files
odoo_source/addons/iap/models/iap_enrich_api.py
T
nounoubensebia 6c81ee556f [REF] [crm_]mail_client_extension, base_setup, crm[_iap_lead_enrich], iap: split mail specific and crm specific code
- split the mail_client_extension module onto two modules:
  1) module mail_client_extension having mail/contact specific code,
  depends on iap and contacts only
  2) module crm_mail_client_extension having crm specific code,
  depends on CRM and mail_client_extension.

  Purpose is to allow the user to use the mail_client_extension
  without needing to install CRM, this will also allow
  the usage of the mail connector in other modules without
  the need for CRM.

- add the module_mail_client_extension field to the
  res_config_settings model of the base_setup module
  in order to enable the user to install the
  mail_client_extension module directly from the settings

- move the crm_lead model from the mail_client_extension_module
  to the newly created crm_mail_client_extension_module, as this
  model is no longer needed by the mail_client_extension module
  because it no longer not implemants CRM functionality

- move the iap_enrich_api model from the crm_iap_lead_enrich
  module onto the iap module as it is only related to contacts
  and not to CRM, this way it can be used in other modules such
  as the mail_client_extension module without the need for CRM
  module

Task-2382870
UPG-PR: https://github.com/odoo/upgrade/pull/2156
COM-PR: https://github.com/odoo/odoo/pull/66139
2021-03-29 11:59:11 +00:00

40 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, api
from odoo.addons.iap.tools import iap_tools
class IapEnrichAPI(models.AbstractModel):
_name = 'iap.enrich.api'
_description = 'IAP Lead Enrichment API'
_DEFAULT_ENDPOINT = 'https://iap-services.odoo.com'
@api.model
def _contact_iap(self, local_endpoint, params):
account = self.env['iap.account'].get('reveal')
dbuuid = self.env['ir.config_parameter'].sudo().get_param('database.uuid')
params['account_token'] = account.account_token
params['dbuuid'] = dbuuid
base_url = self.env['ir.config_parameter'].sudo().get_param('enrich.endpoint', self._DEFAULT_ENDPOINT)
return iap_tools.iap_jsonrpc(base_url + local_endpoint, params=params, timeout=300)
@api.model
def _request_enrich(self, lead_emails):
""" Contact endpoint to get enrichment data.
:param lead_emails: dict{lead_id: email}
:return: dict{lead_id: company data or False}
:raise: several errors, notably
* InsufficientCreditError: {
"credit": 4.0,
"service_name": "reveal",
"base_url": "https://iap.odoo.com/iap/1/credit",
"message": "You don't have enough credits on your account to use this service."
}
"""
params = {
'domains': lead_emails,
}
return self._contact_iap('/iap/clearbit/1/lead_enrichment_email', params=params)