From d4dbd3524ca7e886376d3b4fd79427bdd3e80d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 29 May 2013 15:14:58 +0200 Subject: [PATCH] [FIX] mail, project, project_issue, crm_lead: fixed 'XX Created' subtype not triggered because of condition based on state=new and not state=draft. For tasks, issues and leads, no generic 'Document created' message is posted anymore because of the 'XX Created' message with subtype automatically logged. Generic creation message is logged before automatic subscription to enable message pushing to responsibles. bzr revid: tde@openerp.com-20130529131458-9709ffrsy479hwy3 --- addons/crm/crm_lead.py | 8 +++++--- addons/mail/mail_thread.py | 13 ++++++++++--- addons/project/project.py | 10 ++++++---- addons/project_issue/project_issue.py | 8 +++++--- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 81b29840a03..4436951d083 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -77,12 +77,12 @@ class crm_lead(base_stage, format_address, osv.osv): _track = { 'state': { - 'crm.mt_lead_create': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'new', + 'crm.mt_lead_create': lambda self, cr, uid, obj, ctx=None: obj['state'] in ['new', 'draft'], 'crm.mt_lead_won': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'done', 'crm.mt_lead_lost': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'cancel', }, 'stage_id': { - 'crm.mt_lead_stage': lambda self, cr, uid, obj, ctx=None: obj['state'] not in ['new', 'cancel', 'done'], + 'crm.mt_lead_stage': lambda self, cr, uid, obj, ctx=None: obj['state'] not in ['new', 'draft', 'cancel', 'done'], }, } @@ -103,7 +103,9 @@ class crm_lead(base_stage, format_address, osv.osv): if vals.get('type'): ctx['default_type'] = vals['type'] vals['stage_id'] = self._get_default_stage_id(cr, uid, context=ctx) - return super(crm_lead, self).create(cr, uid, vals, context=context) + # context: no_log, because subtype already handle this + create_context = dict(context, mail_create_nolog=True) + return super(crm_lead, self).create(cr, uid, vals, context=create_context) def _get_default_section_id(self, cr, uid, context=None): """ Gives default section by checking if present in the context """ diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 0ca6a75db85..3103e4da298 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -281,14 +281,21 @@ class mail_thread(osv.AbstractModel): context = {} thread_id = super(mail_thread, self).create(cr, uid, values, context=context) + # automatic logging unless asked not to (mainly for various testing purpose) + if not context.get('mail_create_nolog'): + self.message_post(cr, uid, thread_id, body=_('%s created') % (self._description), context=context) + # subscribe uid unless asked not to if not context.get('mail_create_nosubscribe'): self.message_subscribe_users(cr, uid, [thread_id], [uid], context=context) self.message_auto_subscribe(cr, uid, [thread_id], values.keys(), context=context) - # automatic logging unless asked not to (mainly for various testing purpose) - if not context.get('mail_create_nolog'): - self.message_post(cr, uid, thread_id, body=_('%s created') % (self._description), context=context) + # track values + tracked_fields = self._get_tracked_fields(cr, uid, values.keys(), context=context) + if tracked_fields: + initial_values = {thread_id: dict((item, False) for item in tracked_fields)} + self.message_track(cr, uid, [thread_id], tracked_fields, initial_values, context=context) + return thread_id def write(self, cr, uid, ids, values, context=None): diff --git a/addons/project/project.py b/addons/project/project.py index 23fca695b6b..d911d77c260 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -581,12 +581,12 @@ class task(base_stage, osv.osv): _track = { 'state': { - 'project.mt_task_new': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'new', + 'project.mt_task_new': lambda self, cr, uid, obj, ctx=None: obj['state'] in ['new', 'draft'], 'project.mt_task_started': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'open', 'project.mt_task_closed': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'done', }, 'stage_id': { - 'project.mt_task_stage': lambda self, cr, uid, obj, ctx=None: obj['state'] not in ['new', 'done', 'open'], + 'project.mt_task_stage': lambda self, cr, uid, obj, ctx=None: obj['state'] not in ['new', 'draft', 'done', 'open'], }, 'kanban_state': { # kanban state: tracked, but only block subtype 'project.mt_task_blocked': lambda self, cr, uid, obj, ctx=None: obj['kanban_state'] == 'blocked', @@ -1120,10 +1120,12 @@ class task(base_stage, osv.osv): context = {} if not vals.get('stage_id'): ctx = context.copy() - if vals.get('project_id'): + if vals.get('project_id'): ctx['default_project_id'] = vals['project_id'] vals['stage_id'] = self._get_default_stage_id(cr, uid, context=ctx) - task_id = super(task, self).create(cr, uid, vals, context=context) + # context: no_log, because subtype already handle this + create_context = dict(context, mail_create_nolog=True) + task_id = super(task, self).create(cr, uid, vals, context=create_context) self._store_history(cr, uid, [task_id], context=context) return task_id diff --git a/addons/project_issue/project_issue.py b/addons/project_issue/project_issue.py index bd5dff89413..c334f5f67ef 100644 --- a/addons/project_issue/project_issue.py +++ b/addons/project_issue/project_issue.py @@ -50,12 +50,12 @@ class project_issue(base_stage, osv.osv): _track = { 'state': { - 'project_issue.mt_issue_new': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'new', + 'project_issue.mt_issue_new': lambda self, cr, uid, obj, ctx=None: obj['state'] in ['new', 'draft'], 'project_issue.mt_issue_closed': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'done', 'project_issue.mt_issue_started': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'open', }, 'stage_id': { - 'project_issue.mt_issue_stage': lambda self, cr, uid, obj, ctx=None: obj['state'] not in ['new', 'done', 'open'], + 'project_issue.mt_issue_stage': lambda self, cr, uid, obj, ctx=None: obj['state'] not in ['new', 'draft', 'done', 'open'], }, 'kanban_state': { 'project_issue.mt_issue_blocked': lambda self, cr, uid, obj, ctx=None: obj['kanban_state'] == 'blocked', @@ -70,7 +70,9 @@ class project_issue(base_stage, osv.osv): if vals.get('project_id'): ctx['default_project_id'] = vals['project_id'] vals['stage_id'] = self._get_default_stage_id(cr, uid, context=ctx) - return super(project_issue, self).create(cr, uid, vals, context=context) + # context: no_log, because subtype already handle this + create_context = dict(context, mail_create_nolog=True) + return super(project_issue, self).create(cr, uid, vals, context=create_context) def _get_default_project_id(self, cr, uid, context=None): """ Gives default project by checking if present in the context """