From d22d4dcc23bad33abb06116bbc246c78a858ccaa Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Thu, 31 Aug 2017 14:17:03 +0200 Subject: [PATCH] [FIX] website_crm: fix lead creation through website_form Before this commit, a message received through the contact us form did create a Lead, but any notification was impossible (even if a user was a follower of the relevant sales team. This was because the default sales team is integrated in the values for create in models.py, which mail_thread can't see, but needs in order to notify This commit corrects the behavior which now converge with standard lead creation by adding the default sales_team earlier in the values for create OPW 762651 closes #19180 --- addons/website_crm/models/crm_lead.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/addons/website_crm/models/crm_lead.py b/addons/website_crm/models/crm_lead.py index b9b29aa37ab..1d11290aabf 100644 --- a/addons/website_crm/models/crm_lead.py +++ b/addons/website_crm/models/crm_lead.py @@ -1,12 +1,24 @@ -from openerp import models, SUPERUSER_ID +from openerp import models class Lead(models.Model): _inherit = 'crm.lead' def website_form_input_filter(self, request, values): + defaults = self.default_get(['medium_id', 'team_id']) values['medium_id'] = ( values.get('medium_id') or - self.default_get(['medium_id']).get('medium_id') or + defaults.get('medium_id') or self.sudo().env['ir.model.data'].xmlid_to_res_id('utm.utm_medium_website') ) + + values['team_id'] = values.get('team_id') or defaults.get('team_id') + + if not values['team_id']: + team_model = self.env['ir.model'].search([('model', '=', 'crm.team')]) + lead_model = self.env['ir.model'].search([('model', '=', 'crm.lead')]) + + values['team_id'] = self.env['mail.alias'].search([('alias_model_id', '=', lead_model.id), + ('alias_parent_model_id', '=', team_model.id), + ('alias_name', 'ilike', '%\web%')], limit=1).alias_parent_thread_id + return values