From 65dbf8f11740dda608fe8e7789f7652d97b656bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 26 Aug 2015 10:32:22 +0200 Subject: [PATCH] [IMP] crm, hr, project, sales_team: mail-related fixes - hr, project, sales_team: no subscribe on create For header records like sales steam, project, jobs and department, do not subscribe the creator. Indeed those objects allow to automatically follow child records (opportunities, tasks, issues, applicants). However those records are often created by IT / technical / administrators that should not be followers of all child records. Therefore the no subscribe key is added in context. - crm: new lead subtype The 'new' stage is based on the sequence only, not the probability. Indeed a new lead does not have a probability of 0; otherwise it is already lost. --- addons/crm/crm_lead.py | 2 +- addons/hr/hr.py | 10 ++++++++++ addons/project/project.py | 3 ++- addons/sales_team/sales_team.py | 6 ++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 2ee5588ddc9..c2361939365 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -928,7 +928,7 @@ Update your business card, phone book, social media,... Send an email right now return 'crm.mt_lead_won' elif 'active' in init_values and record.probability == 0 and not record.active: return 'crm.mt_lead_lost' - elif 'stage_id' in init_values and record.probability == 0 and record.stage_id and record.stage_id.sequence <= 1: + elif 'stage_id' in init_values and record.stage_id and record.stage_id.sequence <= 1: return 'crm.mt_lead_create' elif 'stage_id' in init_values: return 'crm.mt_lead_stage' diff --git a/addons/hr/hr.py b/addons/hr/hr.py index ec8f736b3cb..4b3d61c1c63 100644 --- a/addons/hr/hr.py +++ b/addons/hr/hr.py @@ -3,6 +3,7 @@ import logging +from openerp import api from openerp import SUPERUSER_ID from openerp import tools from openerp.modules.module import get_module_resource @@ -103,6 +104,12 @@ class hr_job(osv.Model): }, context=context) return True + # TDE note: done in new api, because called with new api -> context is a + # frozendict -> error when tryign to manipulate it + @api.model + def create(self, values): + return super(hr_job, self.with_context(mail_create_nosubscribe=True)).create(values) + def copy(self, cr, uid, id, default=None, context=None): if default is None: default = {} @@ -308,6 +315,9 @@ class hr_department(osv.osv): return res def create(self, cr, uid, vals, context=None): + if context is None: + context = {} + context['mail_create_nosubscribe'] = True # TDE note: auto-subscription of manager done by hand, because currently # the tracking allows to track+subscribe fields linked to a res.user record # An update of the limited behavior should come, but not currently done. diff --git a/addons/project/project.py b/addons/project/project.py index 633f929927d..cc7e226e59d 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -319,7 +319,8 @@ class project(osv.osv): # Prevent double project creation when 'use_tasks' is checked + alias management create_context = dict(context, project_creation_in_progress=True, alias_model_name=vals.get('alias_model', 'project.task'), - alias_parent_model_name=self._name) + alias_parent_model_name=self._name, + mail_create_nosubscribe=True) if vals.get('type', False) not in ('template', 'contract'): vals['type'] = 'contract' diff --git a/addons/sales_team/sales_team.py b/addons/sales_team/sales_team.py index 8c871b88bbc..ec99ca6bdf2 100644 --- a/addons/sales_team/sales_team.py +++ b/addons/sales_team/sales_team.py @@ -55,6 +55,12 @@ class crm_team(osv.Model): (osv.osv._check_recursion, 'Error ! You cannot create recursive Sales team.', ['parent_id']) ] + def create(self, cr, uid, values, context=None): + if context is None: + context = {} + context['mail_create_nosubscribe'] = True + return super(crm_team, self).create(cr, uid, values, context=context) + def name_get(self, cr, uid, ids, context=None): """Overrides orm name_get method""" if not isinstance(ids, list):