Skip to content
Snippets Groups Projects
Commit a2c7e6e3 authored by jvm-odoo's avatar jvm-odoo Committed by fw-bot
Browse files

[FIX] crm: fix lead/opportunity meeting scheduling


Reproduce the issue:
 - In the CRM app, create a lead/opportunity.
 - Schedule a meeting for this opportunity via
   the chatter and click on create.
 - Go back, the "Meeting" stat button is now at 1
 - Schedule a meeting for this opportunity via
   the chatter and click on edit then create.
 - Go back, the "Meeting" stat button is still at 1

Cause:
When we click directly on create, the opportunity ID is in the defaults
option but when we click on edit, there is no opportunity ID.

So, this commit use the context to retrieve the concerned opportunity
and set it if it is not already set.

I splitted the solution into a private method for a better readability.

OPW-2092920

closes odoo/odoo#39952

X-original-commit: 59d154dc
Signed-off-by: default avatarJason Van Malder <jasonvanmalder@users.noreply.github.com>
parent e4de2b2e
Branches
Tags
No related merge requests found
......@@ -7,6 +7,17 @@ from odoo import api, fields, models
class CalendarEvent(models.Model):
_inherit = 'calendar.event'
def _is_crm_lead(self, defaults, ctx=None):
"""
This method checks if the concerned model is a CRM lead.
The information is not always in the defaults values,
this is why it is necessary to check the context too.
"""
res_model = defaults.get('res_model', False) or ctx and ctx.get('default_res_model')
res_model_id = defaults.get('res_model_id', False) or ctx and ctx.get('default_res_model_id')
return res_model and res_model == 'crm.lead' or res_model_id and self.env['ir.model'].sudo().browse(res_model_id).model == 'crm.lead'
@api.model
def default_get(self, fields):
if self.env.context.get('default_opportunity_id'):
......@@ -17,9 +28,10 @@ class CalendarEvent(models.Model):
defaults = super(CalendarEvent, self).default_get(fields)
# sync res_model / res_id to opportunity id (aka creating meeting from lead chatter)
if 'opportunity_id' not in defaults and defaults.get('res_id') and (defaults.get('res_model') or defaults.get('res_model_id')):
if (defaults.get('res_model') and defaults['res_model'] == 'crm.lead') or (defaults.get('res_model_id') and self.env['ir.model'].sudo().browse(defaults['res_model_id']).model == 'crm.lead'):
defaults['opportunity_id'] = defaults['res_id']
ctx = self.env.context
if 'opportunity_id' not in defaults:
if self._is_crm_lead(defaults, ctx):
defaults['opportunity_id'] = defaults.get('res_id', False) or ctx.get('default_res_id', False)
return defaults
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment