[FIX] crm : fix and add data for pls settings and use null value instead of empty for phone and email state fields
This commit applies multiples things:
- Fix PLS settings that were not loaded correctly (was not using technical field names)
- Add data for PLS settings to check all optional fields and set the start date.
- use null value instead of empty for phone and email state fields to lessen the DB storage
- set pls start date required
Task ID: 2044539
PR #37413
This commit is contained in:
@@ -20,6 +20,14 @@
|
||||
<record id="frequency_field_lang_id" model="crm.lead.scoring.frequency.field">
|
||||
<field name="field_id" eval="ref('crm.field_crm_lead__lang_id')"/>
|
||||
</record>
|
||||
<record id="crm_pls_fields_param" model="ir.config_parameter">
|
||||
<field name="key">crm.pls_fields</field>
|
||||
<field name="value" eval="'state_id,country_id,phone_state,email_state,source_id'"/>
|
||||
</record>
|
||||
<record id="crm_pls_start_date_param" model="ir.config_parameter">
|
||||
<field name="key">crm.pls_start_date</field>
|
||||
<field name="value" eval="DateTime.now().strftime('%Y-%m-%d')"/>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
<record id="website_crm_score_cron" model="ir.cron">
|
||||
|
||||
@@ -110,12 +110,10 @@ class Lead(models.Model):
|
||||
is_automated_probability = fields.Boolean('Is automated probability?', compute="_compute_is_automated_probability")
|
||||
phone_state = fields.Selection([
|
||||
('correct', 'Correct'),
|
||||
('incorrect', 'Incorrect'),
|
||||
('empty', 'Empty')], string='Phone Quality', default="empty", compute="_compute_phone_state", store=True)
|
||||
('incorrect', 'Incorrect')], string='Phone Quality', compute="_compute_phone_state", store=True)
|
||||
email_state = fields.Selection([
|
||||
('correct', 'Correct'),
|
||||
('incorrect', 'Incorrect'),
|
||||
('empty', 'Empty')], string='Email Quality', default="empty", compute="_compute_email_state", store=True)
|
||||
('incorrect', 'Incorrect')], string='Email Quality', compute="_compute_email_state", store=True)
|
||||
|
||||
# Only used for type opportunity
|
||||
planned_revenue = fields.Monetary('Expected Revenue', currency_field='company_currency', tracking=True)
|
||||
@@ -222,7 +220,7 @@ class Lead(models.Model):
|
||||
@api.depends('phone', 'country_id.code')
|
||||
def _compute_phone_state(self):
|
||||
for lead in self:
|
||||
phone_status = 'empty'
|
||||
phone_status = False
|
||||
if lead.phone:
|
||||
country_code = lead.country_id.code if lead.country_id and lead.country_id.code else None
|
||||
try:
|
||||
@@ -235,7 +233,7 @@ class Lead(models.Model):
|
||||
@api.depends('email_from')
|
||||
def _compute_email_state(self):
|
||||
for lead in self:
|
||||
email_state = 'empty'
|
||||
email_state = False
|
||||
if lead.email_from:
|
||||
email_state = 'incorrect'
|
||||
for email in email_split(lead.email_from):
|
||||
@@ -1464,7 +1462,7 @@ class Lead(models.Model):
|
||||
that are defined on the model. """
|
||||
pls_fields_config = self.env['ir.config_parameter'].sudo().get_param('crm.pls_fields')
|
||||
pls_fields = pls_fields_config.split(',') if pls_fields_config else []
|
||||
pls_safe_fields = [field for field in pls_fields if field in self._fields]
|
||||
pls_safe_fields = [field for field in pls_fields if field in self._fields.keys()]
|
||||
return pls_safe_fields
|
||||
|
||||
# Rebuild Frequency Table Tools
|
||||
@@ -1525,7 +1523,7 @@ class Lead(models.Model):
|
||||
lost = result['count'] if result['probability'] == 0 else 0
|
||||
for field in fields:
|
||||
value = result[field]
|
||||
if value:
|
||||
if value or field in ('email_state', 'phone_state'):
|
||||
if field == 'stage_id':
|
||||
if won: # increment all stages if won
|
||||
stages_to_increment = [stage['id'] for stage in stage_ids]
|
||||
@@ -1621,7 +1619,7 @@ class Lead(models.Model):
|
||||
if field == 'team_id': # ignore team_id as stored separately in leads_values_dict[lead_id][team_id]
|
||||
continue
|
||||
value = lead[field]
|
||||
if value:
|
||||
if value or field in ('email_state', 'phone_state'):
|
||||
lead_values.append((field, value))
|
||||
leads_values_dict[lead['id']] = {'values': lead_values, 'team_id': lead['team_id']}
|
||||
|
||||
@@ -1636,7 +1634,7 @@ class Lead(models.Model):
|
||||
if field == 'team_id': # ignore team_id as stored separately in leads_values_dict[lead_id][team_id]
|
||||
continue
|
||||
value = lead[field].id if isinstance(lead[field], models.BaseModel) else lead[field]
|
||||
if value:
|
||||
if value or field in ('email_state', 'phone_state'):
|
||||
lead_values.append((field, value))
|
||||
for tag in lead.tag_ids:
|
||||
lead_values.append(('tag_id', tag.id))
|
||||
|
||||
@@ -16,7 +16,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
module_crm_iap_lead_enrich = fields.Boolean("Enrich your leads automatically with company data based on their email address.")
|
||||
lead_mining_in_pipeline = fields.Boolean("Create a lead mining request directly from the opportunity pipeline.", config_parameter='crm.lead_mining_in_pipeline')
|
||||
predictive_lead_scoring_start_date = fields.Date(string='Lead Scoring Starting Date', compute="_compute_pls_start_date", inverse="_inverse_pls_start_date_str")
|
||||
predictive_lead_scoring_start_date_str = fields.Char(string='Lead Scoring Starting Date in String', default=date.today().strftime('%Y-%m-%d'), config_parameter='crm.pls_start_date')
|
||||
predictive_lead_scoring_start_date_str = fields.Char(string='Lead Scoring Starting Date in String', config_parameter='crm.pls_start_date')
|
||||
predictive_lead_scoring_fields = fields.Many2many('crm.lead.scoring.frequency.field', string='Lead Scoring Frequency Fields', compute="_compute_pls_fields", inverse="_inverse_pls_fields_str")
|
||||
predictive_lead_scoring_fields_str = fields.Char(string='Lead Scoring Frequency Fields in String', config_parameter='crm.pls_fields')
|
||||
|
||||
@@ -39,7 +39,8 @@ class ResConfigSettings(models.TransientModel):
|
||||
for setting in self:
|
||||
if setting.predictive_lead_scoring_fields_str:
|
||||
names = setting.predictive_lead_scoring_fields_str.split(',')
|
||||
setting.predictive_lead_scoring_fields = self.env['crm.lead.scoring.frequency.field'].search([('name', 'in', names)])
|
||||
fields = self.env['ir.model.fields'].search([('name', 'in', names), ('model', '=', 'crm.lead')])
|
||||
setting.predictive_lead_scoring_fields = self.env['crm.lead.scoring.frequency.field'].search([('field_id', 'in', fields.ids)])
|
||||
else:
|
||||
setting.predictive_lead_scoring_fields = None
|
||||
|
||||
@@ -48,7 +49,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
we store the fields with a comma separated string into a Char config field """
|
||||
for setting in self:
|
||||
if setting.predictive_lead_scoring_fields:
|
||||
setting.predictive_lead_scoring_fields_str = ','.join(setting.predictive_lead_scoring_fields.mapped('name'))
|
||||
setting.predictive_lead_scoring_fields_str = ','.join(setting.predictive_lead_scoring_fields.mapped('field_id.name'))
|
||||
else:
|
||||
setting.predictive_lead_scoring_fields_str = ''
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
<div class="mt16">
|
||||
Consider leads created as of the
|
||||
<field name="predictive_lead_scoring_start_date_str" invisible="1"/>
|
||||
<field name="predictive_lead_scoring_start_date"/>
|
||||
<field name="predictive_lead_scoring_start_date" required="1"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user