From a7d029afa715d4d6efa5a67d3a4cd1ff165370e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Debauche=20St=C3=A9phane?= Date: Fri, 15 Nov 2019 15:48:15 +0000 Subject: [PATCH] [FIX] crm_website: fix the type of a lead created with the contact form Lead/Opportunity type ===================== In the settings, if ``group_use_leads`` is checked, we add the group ``use_leads`` to all users in the group ``base.group_user`` To know if the setting is checked, in the model ``crm.lead``, we compute this code, ``` self.env['res.users'].has_group('crm.group_use_lead') ``` In 12.0 ======= When we compute ``sudo``, we are as the admin user. The admin user is in the group ``base.group_user`` and so, he can be in the group ``use_leads``, so everything work fine. In 13.0 ======= When we perform a ``sudo``, we keep the same user. But the visitor is not in the group ``base.group_user`` (he is in the group ``base.group_public``) So, the visitor can never be in the group ``use_leads`` Fix === To fix it, we just need to compute the method ``has_group`` as the super user (which is in the group ``base.group_user``). ``` self.with_user(SUPERUSER_ID).env['res.users'].has_group('crm.group_use_lead') ``` Task #2124421 closes odoo/odoo#40418 X-original-commit: 8758bdc24297032ba8fd65f637a6990c6351dd27 Signed-off-by: Thibault Delavallee (tde) --- addons/website_crm/models/crm_lead.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/website_crm/models/crm_lead.py b/addons/website_crm/models/crm_lead.py index dc929284842..4e62f808870 100644 --- a/addons/website_crm/models/crm_lead.py +++ b/addons/website_crm/models/crm_lead.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import api, fields, models +from odoo import api, fields, models, SUPERUSER_ID class Lead(models.Model): @@ -49,6 +49,7 @@ class Lead(models.Model): request.website.crm_default_team_id.id values['user_id'] = values.get('user_id') or \ request.website.crm_default_user_id.id + values['type'] = 'lead' if self.with_user(SUPERUSER_ID).env['res.users'].has_group('crm.group_use_lead') else 'opportunity' return values