From 554f70f218683ac9ff0ece3f64e90c266883b028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 25 Mar 2016 12:03:33 +0100 Subject: [PATCH] [FIX] crm, hr_recruitment, project_issue: responsible When using the mailgateway, the responsible of the newly created lead / applicant / issue is explicitely set to False since the original mailgateway commit in 2010. However this conflicts with some custom behavior that tries to set the responsible on the same objects. Notably in recruitment the responsible is set to be the recruitment responsible set on the job, if any. In this commit we replace the explicit set of user_id=False to using a default_user_id=False in the context. This way the admin or mailgateway user will not be responsible of every new records. And this enables custom behavior to find a responsible. --- addons/crm/crm_lead.py | 9 +++++++-- addons/hr_recruitment/models/hr_recruitment.py | 6 +++++- addons/project_issue/project_issue.py | 9 +++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 484f628c5c0..43d0b18b0c7 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -1022,6 +1022,12 @@ Update your business card, phone book, social media,... Send an email right now through message_process. This override updates the document according to the email. """ + # remove default author when going through the mail gateway. Indeed we + # do not want to explicitly set user_id to False; however we do not + # want the gateway user to be responsible if no other responsible is + # found. + create_context = dict(context or {}) + create_context['default_user_id'] = False if custom_values is None: custom_values = {} defaults = { @@ -1029,14 +1035,13 @@ Update your business card, phone book, social media,... Send an email right now 'email_from': msg.get('from'), 'email_cc': msg.get('cc'), 'partner_id': msg.get('author_id', False), - 'user_id': False, } if msg.get('author_id'): defaults.update(self.on_change_partner_id(cr, uid, None, msg.get('author_id'), context=context)['value']) if msg.get('priority') in dict(crm_stage.AVAILABLE_PRIORITIES): defaults['priority'] = msg.get('priority') defaults.update(custom_values) - return super(crm_lead, self).message_new(cr, uid, msg, custom_values=defaults, context=context) + return super(crm_lead, self).message_new(cr, uid, msg, custom_values=defaults, context=create_context) def message_update(self, cr, uid, ids, msg, update_vals=None, context=None): """ Overrides mail_thread message_update that is called by the mailgateway diff --git a/addons/hr_recruitment/models/hr_recruitment.py b/addons/hr_recruitment/models/hr_recruitment.py index a6cd84d0445..5d52ca247cd 100644 --- a/addons/hr_recruitment/models/hr_recruitment.py +++ b/addons/hr_recruitment/models/hr_recruitment.py @@ -392,13 +392,17 @@ class Applicant(models.Model): through message_process. This override updates the document according to the email. """ + # remove default author when going through the mail gateway. Indeed we + # do not want to explicitly set user_id to False; however we do not + # want the gateway user to be responsible if no other responsible is + # found. + self = self.with_context(default_user_id=False) val = msg.get('from').split('<')[0] defaults = { 'name': msg.get('subject') or _("No Subject"), 'partner_name': val, 'email_from': msg.get('from'), 'email_cc': msg.get('cc'), - 'user_id': False, 'partner_id': msg.get('author_id', False), } if msg.get('priority'): diff --git a/addons/project_issue/project_issue.py b/addons/project_issue/project_issue.py index 13eb0e14db0..f25eb43e9d9 100644 --- a/addons/project_issue/project_issue.py +++ b/addons/project_issue/project_issue.py @@ -394,6 +394,12 @@ class project_issue(osv.Model): through message_process. This override updates the document according to the email. """ + # remove default author when going through the mail gateway. Indeed we + # do not want to explicitly set user_id to False; however we do not + # want the gateway user to be responsible if no other responsible is + # found. + create_context = dict(context or {}) + create_context['default_user_id'] = False if custom_values is None: custom_values = {} context = dict(context or {}, state_to='draft') @@ -402,11 +408,10 @@ class project_issue(osv.Model): 'email_from': msg.get('from'), 'email_cc': msg.get('cc'), 'partner_id': msg.get('author_id', False), - 'user_id': False, } defaults.update(custom_values) - res_id = super(project_issue, self).message_new(cr, uid, msg, custom_values=defaults, context=context) + res_id = super(project_issue, self).message_new(cr, uid, msg, custom_values=defaults, context=create_context) email_list = self.email_split(cr, uid, [res_id], msg, context=context) partner_ids = filter(None, self._find_partner_from_emails(cr, uid, [res_id], email_list, force_create=False, context=context)) self.message_subscribe(cr, uid, [res_id], partner_ids, context=context)