diff --git a/addons/crm/__manifest__.py b/addons/crm/__manifest__.py
index 55e0bcd8780..722950735fd 100644
--- a/addons/crm/__manifest__.py
+++ b/addons/crm/__manifest__.py
@@ -4,7 +4,7 @@
{
'name': 'CRM',
- 'version': '1.6',
+ 'version': '1.7',
'category': 'Sales/CRM',
'sequence': 15,
'summary': 'Track leads and close opportunities',
diff --git a/addons/crm/data/crm_lead_merge_template.xml b/addons/crm/data/crm_lead_merge_template.xml
index a46087183db..af9e485123b 100644
--- a/addons/crm/data/crm_lead_merge_template.xml
+++ b/addons/crm/data/crm_lead_merge_template.xml
@@ -40,8 +40,8 @@
- Lost Reason:
+
+ Lost Reason:
Created on:
diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py
index 1f3daa6d1c9..61c8adfba25 100644
--- a/addons/crm/models/crm_lead.py
+++ b/addons/crm/models/crm_lead.py
@@ -213,7 +213,7 @@ class Lead(models.Model):
automated_probability = fields.Float('Automated Probability', compute='_compute_probabilities', readonly=True, store=True)
is_automated_probability = fields.Boolean('Is automated probability?', compute="_compute_is_automated_probability")
# Won/Lost
- lost_reason = fields.Many2one(
+ lost_reason_id = fields.Many2one(
'crm.lost.reason', string='Lost Reason',
index=True, ondelete='restrict', tracking=True)
# Statistics
@@ -901,7 +901,7 @@ class Lead(models.Model):
activated = self.filtered(lambda lead: lead.active)
archived = self.filtered(lambda lead: not lead.active)
if activated:
- activated.write({'lost_reason': False})
+ activated.write({'lost_reason_id': False})
activated._compute_probabilities()
if archived:
archived.write({'probability': 0, 'automated_probability': 0})
@@ -1355,9 +1355,9 @@ class Lead(models.Model):
'type': lambda fname, leads: 'opportunity' if any(lead.type == 'opportunity' for lead in leads) else 'lead',
'priority': lambda fname, leads: max(leads.mapped('priority')) if leads else False,
'tag_ids': lambda fname, leads: leads.mapped('tag_ids'),
- 'lost_reason': lambda fname, leads:
+ 'lost_reason_id': lambda fname, leads:
False if leads and leads[0].probability
- else next((lead.lost_reason for lead in leads if lead.lost_reason), False),
+ else next((lead.lost_reason_id for lead in leads if lead.lost_reason_id), False),
}
def _merge_get_fields(self):
@@ -1723,7 +1723,7 @@ class Lead(models.Model):
self.ensure_one()
if 'stage_id' in init_values and self.probability == 100 and self.stage_id:
return self.env.ref('crm.mt_lead_won')
- elif 'lost_reason' in init_values and self.lost_reason:
+ elif 'lost_reason_id' in init_values and self.lost_reason_id:
return self.env.ref('crm.mt_lead_lost')
elif 'stage_id' in init_values:
return self.env.ref('crm.mt_lead_stage')
diff --git a/addons/crm/models/crm_lost_reason.py b/addons/crm/models/crm_lost_reason.py
index 4b848acbc5f..714a984db68 100644
--- a/addons/crm/models/crm_lost_reason.py
+++ b/addons/crm/models/crm_lost_reason.py
@@ -13,8 +13,12 @@ class LostReason(models.Model):
leads_count = fields.Integer('Leads Count', compute='_compute_leads_count')
def _compute_leads_count(self):
- lead_data = self.env['crm.lead'].with_context(active_test=False).read_group([('lost_reason', 'in', self.ids)], ['lost_reason'], ['lost_reason'])
- mapped_data = dict((data['lost_reason'][0], data['lost_reason_count']) for data in lead_data)
+ lead_data = self.env['crm.lead'].with_context(active_test=False).read_group(
+ [('lost_reason_id', 'in', self.ids)],
+ ['lost_reason_id'],
+ ['lost_reason_id']
+ )
+ mapped_data = dict((data['lost_reason_id'][0], data['lost_reason_id_count']) for data in lead_data)
for reason in self:
reason.leads_count = mapped_data.get(reason.id, 0)
@@ -22,7 +26,7 @@ class LostReason(models.Model):
return {
'name': _('Leads'),
'view_mode': 'tree,form',
- 'domain': [('lost_reason', 'in', self.ids)],
+ 'domain': [('lost_reason_id', 'in', self.ids)],
'res_model': 'crm.lead',
'type': 'ir.actions.act_window',
'context': {'create': False, 'active_test': False},
diff --git a/addons/crm/report/crm_opportunity_report_views.xml b/addons/crm/report/crm_opportunity_report_views.xml
index 42347272642..8f8a7432ea6 100644
--- a/addons/crm/report/crm_opportunity_report_views.xml
+++ b/addons/crm/report/crm_opportunity_report_views.xml
@@ -105,7 +105,7 @@
-
+
diff --git a/addons/crm/tests/test_crm_lead_lost.py b/addons/crm/tests/test_crm_lead_lost.py
index 735d3ec2ed3..e7dd92669fc 100644
--- a/addons/crm/tests/test_crm_lead_lost.py
+++ b/addons/crm/tests/test_crm_lead_lost.py
@@ -34,7 +34,7 @@ class TestLeadConvert(crm_common.TestCrmCommon):
self.flush_tracking()
lead = self.env['crm.lead'].browse(self.lead_1.ids)
- self.assertFalse(lead.lost_reason)
+ self.assertFalse(lead.lost_reason_id)
self.assertEqual(lead.probability, 32)
self.assertEqual(len(lead.message_ids), 2, 'Should have tracked new responsible')
update_message = lead.message_ids[0]
@@ -54,7 +54,7 @@ class TestLeadConvert(crm_common.TestCrmCommon):
# check lead update
self.assertFalse(lead.active)
self.assertEqual(lead.automated_probability, 0)
- self.assertEqual(lead.lost_reason, self.lost_reason) # TDE FIXME: should be called lost_reason_id non didjou
+ self.assertEqual(lead.lost_reason_id, self.lost_reason) # TDE FIXME: should be called lost_reason_id non didjou
self.assertEqual(lead.probability, 0)
# check messages
self.assertEqual(len(lead.message_ids), 3, 'Should have logged a tracking message for lost lead with reason')
@@ -64,7 +64,7 @@ class TestLeadConvert(crm_common.TestCrmCommon):
self.assertTracking(
update_message,
[('active', 'boolean', True, False),
- ('lost_reason', 'many2one', False, self.lost_reason)
+ ('lost_reason_id', 'many2one', False, self.lost_reason)
]
)
@@ -90,7 +90,7 @@ class TestLeadConvert(crm_common.TestCrmCommon):
self.assertFalse(lead.active)
self.assertEqual(lead.automated_probability, 0)
self.assertEqual(lead.probability, 0)
- self.assertEqual(lead.lost_reason, self.lost_reason)
+ self.assertEqual(lead.lost_reason_id, self.lost_reason)
# check messages
self.assertEqual(len(lead.message_ids), 3, 'Should have 3 messages: creation, lost, and log')
lost_message = lead.message_ids.filtered(lambda msg: msg.subtype_id == self.env.ref('crm.mt_lead_lost'))
@@ -98,7 +98,7 @@ class TestLeadConvert(crm_common.TestCrmCommon):
self.assertTracking(
lost_message,
[('active', 'boolean', True, False),
- ('lost_reason', 'many2one', False, self.lost_reason)
+ ('lost_reason_id', 'many2one', False, self.lost_reason)
]
)
note_message = lead.message_ids.filtered(lambda msg: msg.subtype_id == self.env.ref('mail.mt_note'))
diff --git a/addons/crm/tests/test_crm_lead_merge.py b/addons/crm/tests/test_crm_lead_merge.py
index bbf73b70155..9f5b8bb2dfa 100644
--- a/addons/crm/tests/test_crm_lead_merge.py
+++ b/addons/crm/tests/test_crm_lead_merge.py
@@ -307,7 +307,7 @@ class TestLeadMerge(TestLeadMergeCommon):
# because "lead_1" is not lost
lost_reason = self.env['crm.lost.reason'].create({'name': 'Test Reason'})
self.lead_w_partner.write({
- 'lost_reason': lost_reason,
+ 'lost_reason_id': lost_reason,
'probability': 0,
})
@@ -317,7 +317,7 @@ class TestLeadMerge(TestLeadMergeCommon):
name='Nibbler Spacecraft Request',
partner_id=self.contact_company_1,
priority='2',
- lost_reason=False,
+ lost_reason_id=False,
tag_ids=all_tags):
leads._merge_opportunity(auto_unlink=False, max_length=None)
@@ -331,11 +331,11 @@ class TestLeadMerge(TestLeadMergeCommon):
})
lost_reason = self.env['crm.lost.reason'].create({'name': 'Test Reason'})
- self.lead_w_partner.lost_reason = lost_reason
+ self.lead_w_partner.lost_reason_id = lost_reason
leads = self.env['crm.lead'].browse(self.leads.ids)._sort_by_confidence_level(reverse=True)
- with self.assertLeadMerged(leads[0], leads, lost_reason=lost_reason):
+ with self.assertLeadMerged(leads[0], leads, lost_reason_id=lost_reason):
leads._merge_opportunity(auto_unlink=False, max_length=None)
@users('user_sales_manager')
diff --git a/addons/crm/views/crm_lead_views.xml b/addons/crm/views/crm_lead_views.xml
index 277d07edb80..44127d2899d 100644
--- a/addons/crm/views/crm_lead_views.xml
+++ b/addons/crm/views/crm_lead_views.xml
@@ -246,7 +246,7 @@
-
+
@@ -985,7 +985,7 @@
-
+
diff --git a/addons/crm/wizard/crm_lead_lost.py b/addons/crm/wizard/crm_lead_lost.py
index f2ca5958544..66b36754c6f 100644
--- a/addons/crm/wizard/crm_lead_lost.py
+++ b/addons/crm/wizard/crm_lead_lost.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from odoo import fields, models, _
+from odoo import fields, models
from odoo.tools.mail import is_html_empty
@@ -18,7 +18,7 @@ class CrmLeadLost(models.TransientModel):
def action_lost_reason_apply(self):
self.ensure_one()
leads = self.env['crm.lead'].browse(self.env.context.get('active_ids'))
- res = leads.action_set_lost(lost_reason=self.lost_reason_id.id)
+ res = leads.action_set_lost(lost_reason_id=self.lost_reason_id.id)
if not is_html_empty(self.lost_feedback):
leads._message_log_batch(
bodies=dict(