New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master lead mining request lba #30189

Closed
wants to merge 4 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@pimodoo
Copy link
Contributor

pimodoo commented Jan 14, 2019

Description of the issue/feature this PR addresses:

Current behavior before PR:

Desired behavior after PR is merged:

--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo robodoo added the seen 🙂 label Jan 14, 2019

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="crm_generate_leads_form" model="ir.ui.view">

This comment has been minimized.

@pimodoo

pimodoo Jan 14, 2019

Author Contributor

Move this view in 'addons/crm_iap_lead/views/crm_iap_lead_views.xml' as it is a view of a model and of a Transient

@pimodoo pimodoo force-pushed the odoo-dev:master-lead-mining-request-lba branch from 7bff8bb Jan 14, 2019

@C3POdoo C3POdoo added the RD label Jan 14, 2019

@lobaudoux lobaudoux force-pushed the odoo-dev:master-lead-mining-request-lba branch Jan 16, 2019

@lobaudoux lobaudoux force-pushed the odoo-dev:master-lead-mining-request-lba branch 3 times, most recently Jan 28, 2019

@robodoo robodoo added the CI 🤖 label Jan 29, 2019

@lobaudoux lobaudoux force-pushed the odoo-dev:master-lead-mining-request-lba branch Jan 31, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Jan 31, 2019

@lobaudoux lobaudoux force-pushed the odoo-dev:master-lead-mining-request-lba branch Jan 31, 2019

@robodoo robodoo removed the CI 🤖 label Jan 31, 2019

@lobaudoux lobaudoux force-pushed the odoo-dev:master-lead-mining-request-lba branch to 78e9d89 Feb 4, 2019

@robodoo robodoo added the CI 🤖 label Feb 4, 2019

)

# Methods responsible for format response data into valid odoo lead data
def _lead_vals_from_response(self, req, data):

This comment has been minimized.

@pimodoo

pimodoo Feb 4, 2019

Author Contributor

it looks very similar to the one defined for reveal, can't we make it @api.model (on lead model), and add differences like rule_id in module reveal?

This comment has been minimized.

@pimodoo

pimodoo Feb 4, 2019

Author Contributor

Create a Helper Class with all those common static method


return lead_vals

def _find_state_id(self, state_code, country_id):

This comment has been minimized.

@pimodoo

pimodoo Feb 4, 2019

Author Contributor

same, @api.model and common to rule

return state_id.id
return False

def _prepare_lead_description(self, company_data):

This comment has been minimized.

@pimodoo

pimodoo Feb 4, 2019

Author Contributor

same, @api.model and common to rule

description += ' %s : %s,' % (key.replace('_', ' ').title(), millify(company_data[key]))
return description

def _format_data_for_message_post(self, result):

This comment has been minimized.

@pimodoo

pimodoo Feb 4, 2019

Author Contributor

same, @api.model and common to rule

@lobaudoux lobaudoux force-pushed the odoo-dev:master-lead-mining-request-lba branch from 78e9d89 Feb 4, 2019

@robodoo robodoo added CI 🤖 and removed CI 🤖 labels Feb 4, 2019

@lobaudoux lobaudoux force-pushed the odoo-dev:master-lead-mining-request-lba branch Feb 6, 2019

@robodoo robodoo removed the CI 🤖 label Feb 6, 2019

@lobaudoux lobaudoux force-pushed the odoo-dev:master-lead-mining-request-lba branch Feb 6, 2019

@robodoo robodoo added the CI 🤖 label Feb 6, 2019

@lobaudoux lobaudoux force-pushed the odoo-dev:master-lead-mining-request-lba branch Feb 6, 2019

@robodoo robodoo removed the CI 🤖 label Feb 6, 2019

technology_ids = fields.Many2many('crm.iap.lead.technology', string='Technologies')

# Contact Generation Filter
contact_number = fields.Integer(string='Number of Contacts', required=True, default=1)

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

contact number shouldn't be required on model, as it is not needed at all if you don't want any contact. set an attrs required in view when contact are requested

_description = 'CRM Lead Mining Request'

name = fields.Char(string='Request Number', required=True, readonly=True, default=lambda self: _('New'))
state = fields.Selection([('draft', 'Draft'), ('pending', 'Pending'), ('done', 'Done')], string='Status', default='draft')

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

required


# Fields for the blue tooltip
lead_number_info = fields.Integer(string='Number of Leads ', related='lead_number', readonly=True)
lead_total_credit = fields.Integer(compute='_compute_lead_total_credit', readonly=True)

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

you can remove readonly = True on computed fields, because a computed field without inverse method is readonly by design

contact_total_credit = fields.Integer(compute='_compute_contact_total_credit', readonly=True)

_sql_constraints = [
('limit_contact_number', 'check(contact_number >= 1 and contact_number <= %d)' % MAX_CONTACT, 'Maximum %d contacts are allowed!' % MAX_CONTACT),

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

are we sure we want to have contact number >=1?

_sql_constraints = [
('limit_contact_number', 'check(contact_number >= 1 and contact_number <= %d)' % MAX_CONTACT, 'Maximum %d contacts are allowed!' % MAX_CONTACT),
('limit_lead_number', 'check(lead_number >= 1)', 'You need to request at least one company!'),
('check_company_size', 'check(company_size_min <= company_size_max)', 'The minimum size of the company should be less than or equal to the maximum size.'),

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

remove all sql constraints, and override the 'create' and 'write' method of lead mining request and send a 'UserError' it's easier to fix in case of trouble and less restrictive.

@api.model
def default_get(self, fields):
res = super(CRMLeadMiningRequest, self).default_get(fields)
if not self.env.user.has_group('crm.group_use_lead'):

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

I think it is not needed, you can create a default method like:
def default_lead_type: if self.env.user.has_group('crm.group_use_lead'): return 'lead' else: return 'opportunity'

et sur le field default=default_lead_type

<field name="name">Lead Generation: Leads/Opportunities Generation</field>
<field name="model_id" ref="model_crm_reveal_rule"/>
<!-- Scheduler for Lead Mining Request -->
<record id="ir_cron_crm_lead_mining_request" model="ir.cron">

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

remove cron

return res

@api.model
def _process_requests(self, autocommit=True):

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

not used as cron removed

break # stops the processing of this request and the following requests
_logger.info('End Lead Mining Requests Processing')

@api.model

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

@api.multi

_logger.info('End Lead Mining Requests Processing')

@api.model
def _prepare_iap_payload(self, req):

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

remove req

Show resolved Hide resolved addons/crm_iap_lead/models/crm_iap_lead_mining_request.py
self.state = 'pending'
if self.name == _('New'):
self.name = self.env['ir.sequence'].next_by_code('crm.iap.lead.mining.request') or _('New')
server_payload = self._prepare_iap_payload(self)

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

self._prepare_iap_payload()

self.state = 'draft'

def action_submit(self):
self.state = 'pending'

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

@api.multi
self.ensure_one()

Show resolved Hide resolved addons/crm_iap_lead/models/crm_iap_lead_mining_request.py
Show resolved Hide resolved addons/crm_iap_lead/models/crm_iap_lead_mining_request.py Outdated
return False
else:
self.env['ir.config_parameter'].sudo().set_param('lead.mining.already_notified', False)
self._create_leads_from_response(req, response['data'])

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

remove rq parameter from function, return response['data'], and self._create_leads_from_response and set state done in 'action_submit' if the response is not False

req.state = 'done'
return True

@api.model

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

@api.multi
self.ensure_one()
remover req from signature

self.env['ir.config_parameter'].sudo().set_param(notification_parameter, True)

@api.model
def lead_vals_from_response(self, record, company_data, people_data):

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

you cannot pass record as parameter, pass different values, lead_type, team_id, tag_ids and user_id as you are working on different models

<widget name="iap_buy_more_credits" service_name="reveal"/>
</div>
</field>
</record>
</odoo>
</odoo>

This comment has been minimized.

@pimodoo

pimodoo Feb 13, 2019

Author Contributor

midding new line

@lobaudoux lobaudoux self-assigned this Feb 13, 2019

_name = 'crm.iap.lead.mining.request'
_description = 'CRM Lead Mining Request'

name = fields.Char(string='Request Number', required=True, readonly=True, default=lambda self: _('New'))

This comment has been minimized.

@pimodoo

pimodoo Feb 14, 2019

Author Contributor

copy = False


@api.multi
@api.returns('self', lambda value: value.id)
def copy(self, default=None):

This comment has been minimized.

@pimodoo

pimodoo Feb 14, 2019

Author Contributor

remove if copy=false is OK

""" This method will get the response from the service and create the leads accordingly """
for data in result:
lead_vals = self._lead_vals_from_response(req, data)
lead = self.env['crm.lead'].create(lead_vals)

This comment has been minimized.

@pimodoo

pimodoo Feb 14, 2019

Author Contributor

lead_vals = []
messages_to_post = {}
for data in result:
lead_vals.append(self._lead_vals_from_response(data))
messages_to_post[data['clearbit_id']] = self.env['crm.iap.lead.helpers'].format_data_for_message_post(data['company_data'], data.get('people_data'))
leads = self.env['crm.lead'].create(lead_vals)
for lead in leads:
if message_to_post.get(lead.reveal_id):
lead.message_post_with_view('crm_iap_lead.lead_message_template', values= message_to_post[lead.reveal_id], subtype_id=self.env.ref('mail.mt_note').id)

@lobaudoux lobaudoux force-pushed the odoo-dev:master-lead-mining-request-lba branch from 08b059f to 2b564e5 Feb 14, 2019

@robodoo robodoo removed the CI 🤖 label Feb 14, 2019

@lobaudoux lobaudoux force-pushed the odoo-dev:master-lead-mining-request-lba branch from 2b564e5 to 332e3c2 Feb 14, 2019

[ADD] reveal_service : allow user to generate leads based on filters
Purpose :

Allow the user to generate a certain number of leads based on certain criteria like localization, technologies used, or size.

Available filters are :

- company size
- localization (country and states)
- industries
- technologies

The user can also ask for a few contacts that can be filtered based on
their role or seniority.

Each company found generates a new lead/opportunity for which the sales
team, salesperson and tags can be preset from the lead mining request.

This commit includes the followings changes :

- New module crm_iap_lead
- New model crm.iap.lead.helpers which contains helper methods used by
both modules crm_iap_lead and crm_iap_lead_website
- New model crm.iap.lead.mining.request that holds the data of a lead
mining request
- An option in the CRM settings to install this feature
- New button 'Generate Leads' in the leads/opportunity ListView and
KanbanView that opens a modal allowing to create a lead mining request
- New section 'Lead Generation' in menuitem 'Configuration' of CRM

TaskID : 1902172

@lobaudoux lobaudoux force-pushed the odoo-dev:master-lead-mining-request-lba branch from 332e3c2 to 09a53a6 Feb 14, 2019

@pimodoo

This comment has been minimized.

Copy link
Contributor Author

pimodoo commented Feb 14, 2019

robodoo r+ rebase-ff

@robodoo robodoo added the r+ 👌 label Feb 14, 2019

@robodoo

This comment has been minimized.

Copy link
Contributor

robodoo commented Feb 14, 2019

Merge method set to rebase and fast-forward

@robodoo robodoo added the CI 🤖 label Feb 14, 2019

robodoo pushed a commit that referenced this pull request Feb 14, 2019

[ADD] reveal_service : allow user to generate leads based on filters
Purpose :

Allow the user to generate a certain number of leads based on certain criteria like localization, technologies used, or size.

Available filters are :

- company size
- localization (country and states)
- industries
- technologies

The user can also ask for a few contacts that can be filtered based on
their role or seniority.

Each company found generates a new lead/opportunity for which the sales
team, salesperson and tags can be preset from the lead mining request.

This commit includes the followings changes :

- New module crm_iap_lead
- New model crm.iap.lead.helpers which contains helper methods used by
both modules crm_iap_lead and crm_iap_lead_website
- New model crm.iap.lead.mining.request that holds the data of a lead
mining request
- An option in the CRM settings to install this feature
- New button 'Generate Leads' in the leads/opportunity ListView and
KanbanView that opens a modal allowing to create a lead mining request
- New section 'Lead Generation' in menuitem 'Configuration' of CRM

TaskID : 1902172

closes #30189
@robodoo

This comment has been minimized.

Copy link
Contributor

robodoo commented Feb 14, 2019

Merged, thanks!

@robodoo robodoo closed this Feb 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment