Permalink
Browse files

[WIP] lead_mining new feature

  • Loading branch information...
pimodoo authored and lobaudoux committed Jan 14, 2019
1 parent 3138f5d commit 54ca432f46e32daaf844a7229031b45531773c52
@@ -11,7 +11,9 @@ class ResConfigSettings(models.TransientModel):
generate_lead_from_alias = fields.Boolean('Manual Assignation of Emails', config_parameter='crm.generate_lead_from_alias')
group_use_lead = fields.Boolean(string="Leads", implied_group='crm.group_use_lead')
module_crm_phone_validation = fields.Boolean("Phone Formatting")
module_crm_iap_lead = fields.Boolean("Generate new leads based on their country, technologies, size, etc.")
module_crm_iap_lead_website = fields.Boolean("Create Leads/Opportunities from your website's traffic")
lead_mining_in_pipeline = fields.Boolean("Create a lead mining request directly from the opportunity pipeline.", config_parameter='crm.lead_mining_in_pipeline')

def _find_default_lead_alias_id(self):
alias = self.env.ref('crm.mail_alias_lead_info', False)
@@ -52,14 +52,30 @@
</div>
</div>
</div>

<div class="row mt16 o_settings_container">
<div class="col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="module_crm_iap_lead"/>
</div>

<div class="o_setting_right_pane" id="crm_iap_lead_settings">
<label string="Lead Mining" for="module_crm_iap_lead"/>
<div class="text-muted">
Generate new leads based on their country, technologies, size, etc.
</div>
</div>
</div>
</div>

<div class="row mt16 o_settings_container">
<div class="col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="module_crm_iap_lead_website"/>
</div>

<div class="o_setting_right_pane crm_reveal_settings">
<label string="Website Lead Generation" for="module_crm_reveal"/>
<div class="o_setting_right_pane" id="crm_iap_lead_website_settings">
<label string="Website Lead Generation" for="module_crm_iap_lead_website"/>
<div class="text-muted">
Convert visitors of your website into leads and perform data enrichment based on their IP address.
</div>
@@ -10,8 +10,17 @@
'data/crm.iap.lead.industry.csv',
'data/crm.iap.lead.role.csv',
'data/crm.iap.lead.seniority.csv',
'data/crm.iap.lead.technology.csv',
'data/message_template.xml',
'data/crm_iap_lead_data.xml',
'data/ir_sequence_data.xml',
'security/ir.model.access.csv',
'views/crm_lead_view.xml',
'views/crm_iap_lead_views.xml',
'views/res_config_settings_views.xml',
'views/crm_iap_lead_templates.xml',
],
'qweb': [
'static/src/xml/leads_tree_generate_leads_views.xml',
]
}

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,6 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- Scheduler for Lead Mining Request -->
<record id="ir_cron_crm_lead_mining_request" model="ir.cron">
<field name="name">Lead Generation: Lead Mining Request</field>
<field name="model_id" ref="model_crm_iap_lead_mining_request"/>
<field name="state">code</field>
<field name="code">model._process_requests()</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
</record>

<record id="lead_generation_no_credits" model="mail.template">
<field name="name">IAP Lead Generation Notification</field>
<field name="email_from">iap@odoo.com</field>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- Sequences for lead mining requests -->
<record id="seq_crm_iap_lead_mining_request" model="ir.sequence">
<field name="name">Lead Mining Request</field>
<field name="code">crm.iap.lead.mining.request</field>
<field name="prefix">LMR</field>
<field name="padding">3</field>
<field name="company_id" eval="False"/>
</record>

</data>
</odoo>
@@ -2,3 +2,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import crm_lead
from . import crm_iap_lead
from . import crm_iap_lead_helpers
from . import crm_iap_lead_mining_request
@@ -48,3 +48,16 @@ class PeopleSeniority(models.Model):
@api.depends('name')
def name_get(self):
return [(seniority.id, seniority.name.replace('_', ' ').title()) for seniority in self]


class TechnologyTag(models.Model):
""" Technology Tags of Clearbit """
_name = 'crm.iap.lead.technology'
_description = 'Technology Tag'

name = fields.Char(string='Name', required=True, translate=True)
tech_tag = fields.Char(string="Tech Tag", required=True)

_sql_constraints = [
('name_uniq', 'unique (name)', 'Technology tag name already exists!'),
]
@@ -0,0 +1,121 @@
from math import floor, log10
from odoo import api, models


class CRMHelpers(models.Model):
_name = 'crm.iap.lead.helpers'
_description = 'Helper methods for crm_iap_lead modules'

@api.model
def notify_no_more_credit(self, service_name, model_name, notification_parameter):
"""
Notify about the number of credit.
In order to avoid to spam people each hour, an ir.config_parameter is set
"""
already_notified = self.env['ir.config_parameter'].sudo().get_param(notification_parameter, False)
if already_notified:
return
mail_template = self.env.ref('crm_iap_lead.lead_generation_no_credits')
iap_account = self.env['iap.account'].search([('service_name', '=', service_name)], limit=1)
# Get the email address of the creators of the records
res = self.env[model_name].search_read([], ['create_uid'])
uids = set(r['create_uid'][0] for r in res if r.get('create_uid'))
res = self.env['res.users'].search_read([('id', 'in', list(uids))], ['email'])
emails = set(r['email'] for r in res if r.get('email'))

mail_values = mail_template.generate_email(iap_account.id)
mail_values['email_to'] = ','.join(emails)
mail = self.env['mail.mail'].create(mail_values)
mail.send()
self.env['ir.config_parameter'].sudo().set_param(notification_parameter, True)

@api.model
def lead_vals_from_response(self, record, company_data, people_data):
country_id = self.env['res.country'].search([('code', '=', company_data['country_code'])]).id
website_url = 'https://www.%s' % company_data['domain'] if company_data['domain'] else False
lead_vals = {
# Lead vals from record itself
'type': record.lead_type,
'team_id': record.team_id.id,
'tag_ids': [(6, 0, record.tag_ids.ids)],
'user_id': record.user_id.id,
'reveal_id': company_data['clearbit_id'],
# Lead vals from data
'name': company_data['name'],
'partner_name': company_data['legal_name'] or company_data['name'],
'email_from': ",".join(company_data['email'] or []),
'phone': company_data['phone'] or (company_data['phone_numbers'] and company_data['phone_numbers'][0]) or '',
'website': website_url,
'street': company_data['location'],
'city': company_data['city'],
'zip': company_data['postal_code'],
'country_id': country_id,
'state_id': self._find_state_id(company_data['state_code'], country_id),
'description': self._prepare_lead_description(company_data),
}

# If type is people then add first contact in lead data
if people_data:
lead_vals.update({
'contact_name': people_data[0]['full_name'],
'email_from': people_data[0]['email'],
'function': people_data[0]['title'],
})
return lead_vals

@api.model
def _find_state_id(self, state_code, country_id):
state_id = self.env['res.country.state'].search([('code', '=', state_code), ('country_id', '=', country_id)])
if state_id:
return state_id.id
return False

@api.model
def _prepare_lead_description(self, reveal_data):
description = ''
if reveal_data['sector']:
description += reveal_data['sector']
if reveal_data['website_title']:
description += '\n' + reveal_data['website_title']
if reveal_data['twitter_bio']:
description += '\n' + "Twitter Bio: " + reveal_data['twitter_bio']
if reveal_data['twitter_followers']:
description += ('\nTwitter %s followers, %s \n') % (reveal_data['twitter_followers'], reveal_data['twitter_location'] or '')

numbers = ['raised', 'market_cap', 'employees', 'estimated_annual_revenue']
millnames = ['', ' K', ' M', ' B', 'T']

def millify(n):
try:
n = float(n)
millidx = max(0, min(len(millnames) - 1, int(floor(0 if n == 0 else log10(abs(n)) / 3))))
return '{:.0f}{}'.format(n / 10**(3 * millidx), millnames[millidx])
except Exception:
return n

for key in numbers:
if reveal_data.get(key):
description += ' %s : %s,' % (key.replace('_', ' ').title(), millify(reveal_data[key]))
return description

@api.model
def format_data_for_message_post(self, company_data, people_data):
log_data = {
'twitter': company_data['twitter'],
'description': company_data['description'],
'logo': company_data['logo'],
'name': company_data['name'],
'phone_numbers': company_data['phone_numbers'],
'facebook': company_data['facebook'],
'linkedin': company_data['linkedin'],
'crunchbase': company_data['crunchbase'],
'tech': [t.replace('_', ' ').title() for t in company_data['tech']],
'people_data': people_data,
}
timezone = company_data['timezone']
if timezone:
log_data.update({
'timezone': timezone.replace('_', ' ').title(),
'timezone_url': company_data['timezone_url'],
})
return log_data
Oops, something went wrong.

0 comments on commit 54ca432

Please sign in to comment.