From d24f2970544234c874cfb6a072d201b90a027c93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 18 Dec 2012 16:36:01 +0100 Subject: [PATCH] [REF] Project, task: added tracked fields, added modified auto subscription, removed now unnecessary chatter messages. bzr revid: tde@openerp.com-20121218153601-advl23p0stjg5ylc --- addons/project/project.py | 100 ++++++++------------------------ addons/project/project_data.xml | 57 ++++++++++++------ 2 files changed, 62 insertions(+), 95 deletions(-) diff --git a/addons/project/project.py b/addons/project/project.py index bcde18df786..8e9eb47ba12 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -309,9 +309,7 @@ class project(osv.osv): task_obj = self.pool.get('project.task') task_ids = task_obj.search(cr, uid, [('project_id', 'in', ids), ('state', 'not in', ('cancelled', 'done'))]) task_obj.case_close(cr, uid, task_ids, context=context) - self.write(cr, uid, ids, {'state':'close'}, context=context) - self.set_close_send_note(cr, uid, ids, context=context) - return True + return self.write(cr, uid, ids, {'state':'close'}, context=context) def set_cancel(self, cr, uid, ids, context=None): task_obj = self.pool.get('project.task') @@ -320,19 +318,13 @@ class project(osv.osv): return self.write(cr, uid, ids, {'state':'cancelled'}, context=context) def set_pending(self, cr, uid, ids, context=None): - self.write(cr, uid, ids, {'state':'pending'}, context=context) - self.set_pending_send_note(cr, uid, ids, context=context) - return True + return self.write(cr, uid, ids, {'state':'pending'}, context=context) def set_open(self, cr, uid, ids, context=None): - self.write(cr, uid, ids, {'state':'open'}, context=context) - self.set_open_send_note(cr, uid, ids, context=context) - return True + return self.write(cr, uid, ids, {'state':'open'}, context=context) def reset_project(self, cr, uid, ids, context=None): - res = self.setActive(cr, uid, ids, value=True, context=context) - self.set_open_send_note(cr, uid, ids, context=context) - return res + return self.setActive(cr, uid, ids, value=True, context=context) def map_tasks(self, cr, uid, old_project_id, new_project_id, context=None): """ copy and map tasks from old to new project """ @@ -551,21 +543,8 @@ def Project(): vals['type'] = 'contract' project_id = super(project, self).create(cr, uid, vals, context) mail_alias.write(cr, uid, [vals['alias_id']], {'alias_defaults': {'project_id': project_id} }, context) - self.create_send_note(cr, uid, [project_id], context=context) return project_id - def create_send_note(self, cr, uid, ids, context=None): - return self.message_post(cr, uid, ids, body=_("Project has been created."), context=context) - - def set_open_send_note(self, cr, uid, ids, context=None): - return self.message_post(cr, uid, ids, body=_("Project has been opened."), context=context) - - def set_pending_send_note(self, cr, uid, ids, context=None): - return self.message_post(cr, uid, ids, body=_("Project is now pending."), context=context) - - def set_close_send_note(self, cr, uid, ids, context=None): - return self.message_post(cr, uid, ids, body=_("Project has been closed."), context=context) - def write(self, cr, uid, ids, vals, context=None): # if alias_model has been changed, update alias_model_id accordingly if vals.get('alias_model'): @@ -579,6 +558,17 @@ class task(base_stage, osv.osv): _date_name = "date_start" _inherit = ['mail.thread', 'ir.needaction_mixin'] + _track = { + 'stage_id': { + 'project.mt_project_task_closed': lambda self, cr, uid, obj, ctx=None: obj.stage_id and obj.stage_id.state == 'done', + 'project.mt_project_task_started': lambda self, cr, uid, obj, ctx=None: obj.stage_id and obj.stage_id.state == 'open', + 'project.mt_project_task_stage': lambda self, cr, uid, obj, ctx=None: obj.stage_id and obj.stage_id.state not in ['done', 'open'], + }, + 'kanban_state': { # kanban state: tracked, but only block subtype + 'project.mt_project_task_blocked': lambda self, cr, uid, obj, ctx=None: obj.kanban_state == 'blocked', + }, + } + def _get_default_project_id(self, cr, uid, context=None): """ Gives default section by checking if present in the context """ return (self._resolve_project_id_from_context(cr, uid, context=context) or False) @@ -738,7 +728,7 @@ class task(base_stage, osv.osv): 'description': fields.text('Description'), 'priority': fields.selection([('4','Very Low'), ('3','Low'), ('2','Medium'), ('1','Important'), ('0','Very important')], 'Priority', select=True), 'sequence': fields.integer('Sequence', select=True, help="Gives the sequence order when displaying a list of tasks."), - 'stage_id': fields.many2one('project.task.type', 'Stage', tracked=True, + 'stage_id': fields.many2one('project.task.type', 'Stage', track_visibility=1, domain="['&', ('fold', '=', False), ('project_ids', '=', project_id)]"), 'state': fields.related('stage_id', 'state', type="selection", store=True, selection=_TASK_STATE, string="Status", readonly=True, @@ -749,6 +739,7 @@ class task(base_stage, osv.osv): set to \'Pending\'.'), 'categ_ids': fields.many2many('project.category', string='Tags'), 'kanban_state': fields.selection([('normal', 'Normal'),('blocked', 'Blocked'),('done', 'Ready for next stage')], 'Kanban State', + track_visibility=1, help="A task's kanban state indicates special situations affecting it:\n" " * Normal is the default situation\n" " * Blocked indicates something is preventing the progress of this task\n" @@ -758,7 +749,7 @@ class task(base_stage, osv.osv): 'date_start': fields.datetime('Starting Date',select=True), 'date_end': fields.datetime('Ending Date',select=True), 'date_deadline': fields.date('Deadline',select=True), - 'project_id': fields.many2one('project.project', 'Project', ondelete='set null', select="1", tracked=True), + 'project_id': fields.many2one('project.project', 'Project', ondelete='set null', select="1", track_visibility=1), 'parent_ids': fields.many2many('project.task', 'project_task_parent_rel', 'task_id', 'parent_id', 'Parent Tasks'), 'child_ids': fields.many2many('project.task', 'project_task_parent_rel', 'parent_id', 'task_id', 'Delegated Tasks'), 'notes': fields.text('Notes'), @@ -784,7 +775,7 @@ class task(base_stage, osv.osv): 'project.task': (lambda self, cr, uid, ids, c={}: ids, ['work_ids', 'remaining_hours', 'planned_hours'], 10), 'project.task.work': (_get_task, ['hours'], 10), }), - 'user_id': fields.many2one('res.users', 'Assigned to', tracked=True), + 'user_id': fields.many2one('res.users', 'Assigned to', track_visibility=1), 'delegated_user_id': fields.related('child_ids', 'user_id', type='many2one', relation='res.users', string='Delegated To'), 'partner_id': fields.many2one('res.partner', 'Customer'), 'work_ids': fields.one2many('project.task.work', 'task_id', 'Work done'), @@ -969,14 +960,12 @@ class task(base_stage, osv.osv): if not task.date_end: vals['date_end'] = fields.datetime.now() self.case_set(cr, uid, [task.id], 'done', vals, context=context) - self.case_close_send_note(cr, uid, [task.id], context=context) return True def do_reopen(self, cr, uid, ids, context=None): for task in self.browse(cr, uid, ids, context=context): project = task.project_id self.case_set(cr, uid, [task.id], 'open', {}, context=context) - self.case_open_send_note(cr, uid, [task.id], context) return True def do_cancel(self, cr, uid, ids, context=None): @@ -996,26 +985,21 @@ class task(base_stage, osv.osv): def case_open(self, cr, uid, ids, context=None): if not isinstance(ids,list): ids = [ids] - self.case_set(cr, uid, ids, 'open', {'date_start': fields.datetime.now()}, context=context) - self.case_open_send_note(cr, uid, ids, context) - return True + return self.case_set(cr, uid, ids, 'open', {'date_start': fields.datetime.now()}, context=context) def do_draft(self, cr, uid, ids, context=None): """ Compatibility when changing to case_draft. """ return self.case_draft(cr, uid, ids, context=context) def case_draft(self, cr, uid, ids, context=None): - self.case_set(cr, uid, ids, 'draft', {}, context=context) - self.case_draft_send_note(cr, uid, ids, context=context) - return True + return self.case_set(cr, uid, ids, 'draft', {}, context=context) def do_pending(self, cr, uid, ids, context=None): """ Compatibility when changing to case_pending. """ return self.case_pending(cr, uid, ids, context=context) def case_pending(self, cr, uid, ids, context=None): - self.case_set(cr, uid, ids, 'pending', {}, context=context) - return self.case_pending_send_note(cr, uid, ids, context=context) + return self.case_set(cr, uid, ids, 'pending', {}, context=context) def _delegate_task_attachments(self, cr, uid, task_id, delegated_task_id, context=None): attachment = self.pool.get('ir.attachment') @@ -1078,14 +1062,10 @@ class task(base_stage, osv.osv): return self.set_remaining_time(cr, uid, ids, 10.0, context) def set_kanban_state_blocked(self, cr, uid, ids, context=None): - self.write(cr, uid, ids, {'kanban_state': 'blocked'}, context=context) - self.case_block_send_note(cr, uid, ids, context=context) - return True + return self.write(cr, uid, ids, {'kanban_state': 'blocked'}, context=context) def set_kanban_state_normal(self, cr, uid, ids, context=None): - self.write(cr, uid, ids, {'kanban_state': 'normal'}, context=context) - self.case_open_send_note(cr, uid, ids, context=context) - return True + return self.write(cr, uid, ids, {'kanban_state': 'normal'}, context=context) def set_kanban_state_done(self, cr, uid, ids, context=None): self.write(cr, uid, ids, {'kanban_state': 'done'}, context=context) @@ -1107,11 +1087,6 @@ class task(base_stage, osv.osv): def create(self, cr, uid, vals, context=None): task_id = super(task, self).create(cr, uid, vals, context=context) - project_id = self.browse(cr, uid, task_id, context=context).project_id - if project_id: - # subscribe project followers to the task - self._subscribe_followers_subtype(cr, uid, [task_id], project_id, 'project.project', context=context) - self._store_history(cr, uid, [task_id], context=context) return task_id @@ -1243,33 +1218,6 @@ class task(base_stage, osv.osv): res = super(task, self).message_get_monitored_follower_fields(cr, uid, ids, context=context) return res + ['user_id', 'manager_id'] - def create_send_note(self, cr, uid, ids, context=None): - return self.message_post(cr, uid, ids, body=_("Task created."), subtype="project.mt_task_new", context=context) - - def stage_set_send_note(self, cr, uid, ids, stage_id, context=None): - """ Override of the (void) default notification method. """ - stage_name = self.pool.get('project.task.type').name_get(cr, uid, [stage_id], context=context)[0][1] - return self.message_post(cr, uid, ids, body=_("Stage changed to %s.") % (stage_name), - context=context) - - def case_open_send_note(self, cr, uid, ids, context=None): - return self.message_post(cr, uid, ids, body=_("Task started."), subtype="project.mt_task_started", context=context) - - def case_close_send_note(self, cr, uid, ids, context=None): - return self.message_post(cr, uid, ids, body=_("Task closed."), subtype="project.mt_task_closed", context=context) - - def case_block_send_note(self, cr, uid, ids, context=None): - return self.message_post(cr, uid, ids, body=_("Task blocked."), subtype="project.mt_task_blocked", context=context) - - def case_draft_send_note(self, cr, uid, ids, context=None): - return self.message_post(cr, uid, ids, body=_('Task set as draft.'), context=context) - - def do_delegation_send_note(self, cr, uid, ids, context=None): - for task in self.browse(cr, uid, ids, context=context): - msg = _('Task has been delegated to %s.') % (task.user_id.name) - self.message_post(cr, uid, [task.id], body=msg, context=context) - return True - def project_task_reevaluate(self, cr, uid, ids, context=None): if self.pool.get('res.users').has_group(cr, uid, 'project.group_time_work_estimation_tasks'): return { diff --git a/addons/project/project_data.xml b/addons/project/project_data.xml index cde0cdff974..49375a36a23 100644 --- a/addons/project/project_data.xml +++ b/addons/project/project_data.xml @@ -78,25 +78,6 @@ - - - Task Created - project.project - - - - Task Started - project.project - - - - Task Blocked - project.project - - - Task Done - project.project - Task Created @@ -116,6 +97,44 @@ Task Done project.task + + Stage Changed + project.task + Stage <b>changed</b> + + + + Task Created + project.project + + + project_id + + + Task Started + project.project + + + project_id + + + Task Blocked + project.project + + project_id + + + Task Done + project.project + + project_id + + + Stage Changed + project.project + + project_id +