[FIX] project_issue: fixed subtype implementation, about followers of project automatically following issues. Updated subtype names.
bzr revid: tde@openerp.com-20121102154154-o8dpil045ub2spbd
This commit is contained in:
parent
d8a67f02f8
commit
3450efc109
|
@ -1151,7 +1151,9 @@ 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)
|
||||
# subscribe project followers to the task
|
||||
self._subscribe_project_followers_to_task(cr, uid, task_id, context=context)
|
||||
|
||||
self._store_history(cr, uid, [task_id], context=context)
|
||||
self.create_send_note(cr, uid, [task_id], context=context)
|
||||
return task_id
|
||||
|
@ -1177,6 +1179,8 @@ class task(base_stage, osv.osv):
|
|||
result = super(task, self).write(cr, uid, ids, vals, context=context)
|
||||
if ('stage_id' in vals) or ('remaining_hours' in vals) or ('user_id' in vals) or ('state' in vals) or ('kanban_state' in vals):
|
||||
self._store_history(cr, uid, ids, context=context)
|
||||
|
||||
# subscribe new project followers to the task
|
||||
if vals.get('project_id'):
|
||||
for id in ids:
|
||||
self._subscribe_project_followers_to_task(cr, uid, id, context=context)
|
||||
|
|
|
@ -86,37 +86,37 @@
|
|||
|
||||
<!-- mail: subtypes -->
|
||||
<record id="mt_project_new" model="mail.message.subtype">
|
||||
<field name="name">New Task</field>
|
||||
<field name="name">New</field>
|
||||
<field name="res_model">project.project</field>
|
||||
<field name="default" eval="False"/>
|
||||
</record>
|
||||
<record id="mt_project_closed" model="mail.message.subtype">
|
||||
<field name="name">Task Closed</field>
|
||||
<field name="name">Closed</field>
|
||||
<field name="res_model">project.project</field>
|
||||
</record>
|
||||
<record id="mt_project_canceled" model="mail.message.subtype">
|
||||
<field name="name">Task Canceled</field>
|
||||
<field name="name">Canceled</field>
|
||||
<field name="res_model">project.project</field>
|
||||
</record>
|
||||
<record id="mt_project_stage" model="mail.message.subtype">
|
||||
<field name="name">Task Stage Changed</field>
|
||||
<field name="name">Stage Changed</field>
|
||||
<field name="res_model">project.project</field>
|
||||
</record>
|
||||
|
||||
<record id="mt_task_new" model="mail.message.subtype">
|
||||
<field name="name">New Task</field>
|
||||
<field name="name">New</field>
|
||||
<field name="res_model">project.task</field>
|
||||
</record>
|
||||
<record id="mt_task_closed" model="mail.message.subtype">
|
||||
<field name="name">Task Closed</field>
|
||||
<field name="name">Closed</field>
|
||||
<field name="res_model">project.task</field>
|
||||
</record>
|
||||
<record id="mt_task_canceled" model="mail.message.subtype">
|
||||
<field name="name">Task Canceled</field>
|
||||
<field name="name">Canceled</field>
|
||||
<field name="res_model">project.task</field>
|
||||
</record>
|
||||
<record id="mt_task_change" model="mail.message.subtype">
|
||||
<field name="name">Task Stage Changed</field>
|
||||
<field name="name">Stage Changed</field>
|
||||
<field name="res_model">project.task</field>
|
||||
</record>
|
||||
|
||||
|
|
|
@ -359,31 +359,44 @@ class project_issue(base_stage, osv.osv):
|
|||
return super(project_issue, self).copy(cr, uid, id, default=default,
|
||||
context=context)
|
||||
|
||||
def _subscribe_project_followers_to_issue(self, cr, uid, task_id, context=None):
|
||||
# task followers are project followers, with matching subtypes
|
||||
task_record = self.browse(cr, uid, task_id, context=context)
|
||||
subtype_obj = self.pool.get('mail.message.subtype')
|
||||
follower_obj = self.pool.get('mail.followers')
|
||||
if task_record.project_id:
|
||||
# create mapping
|
||||
task_subtype_ids = subtype_obj.search(cr, uid, ['|', ('res_model', '=', False), ('res_model', '=', self._name)], context=context)
|
||||
task_subtypes = subtype_obj.browse(cr, uid, task_subtype_ids, context=context)
|
||||
# fetch subscriptions
|
||||
follower_ids = follower_obj.search(cr, uid, [('res_model', '=', 'project.project'), ('res_id', '=', task_record.project_id.id)], context=context)
|
||||
# copy followers
|
||||
for follower in follower_obj.browse(cr, uid, follower_ids, context=context):
|
||||
if not follower.subtype_ids:
|
||||
continue
|
||||
project_subtype_names = [project_subtype.name for project_subtype in follower.subtype_ids]
|
||||
task_subtype_ids = [task_subtype.id for task_subtype in task_subtypes if task_subtype.name in project_subtype_names]
|
||||
self.message_subscribe(cr, uid, [task_id], [follower.partner_id.id],
|
||||
subtype_ids=task_subtype_ids, context=context)
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
#Update last action date every time the user change the stage, the state or send a new email
|
||||
logged_fields = ['stage_id', 'state', 'message_ids']
|
||||
subtype_obj = self.pool.get('mail.message.subtype')
|
||||
name = False
|
||||
if any([field in vals for field in logged_fields]):
|
||||
vals['date_action_last'] = time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
# subscribe new project followers to the issue
|
||||
if vals.get('project_id'):
|
||||
project_id = self.pool.get('project.project').browse(cr, uid, vals.get('project_id'), context=context)
|
||||
for key in project_id.message_subtype_data:
|
||||
if key == 'New Task' and project_id.message_subtype_data[key]['default'] == True:
|
||||
name = 'created'
|
||||
if key == 'Task Closed' and project_id.message_subtype_data[key]['default'] == True:
|
||||
name = 'closed'
|
||||
subtype_ids = subtype_obj.search(cr, uid, [('res_model', '=', self._name), ('name', 'ilike', name)], context=context)
|
||||
subtype_obj.write(cr,uid, subtype_ids, {'default': project_id.message_subtype_data[key]['default']},context=context)
|
||||
vals['message_follower_ids'] = [(4, follower.id) for follower in project_id.message_follower_ids]
|
||||
for id in ids:
|
||||
self._subscribe_project_followers_to_issue(cr, uid, id, context=context)
|
||||
|
||||
return super(project_issue, self).write(cr, uid, ids, vals, context)
|
||||
|
||||
def onchange_task_id(self, cr, uid, ids, task_id, context=None):
|
||||
if not task_id:
|
||||
return {'value':{}}
|
||||
return {'value': {}}
|
||||
task = self.pool.get('project.task').browse(cr, uid, task_id, context=context)
|
||||
return {'value':{'user_id': task.user_id.id,}}
|
||||
return {'value': {'user_id': task.user_id.id, }}
|
||||
|
||||
def case_reset(self, cr, uid, ids, context=None):
|
||||
"""Resets case as draft
|
||||
|
@ -393,21 +406,12 @@ class project_issue(base_stage, osv.osv):
|
|||
return res
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
subtype_obj = self.pool.get('mail.message.subtype')
|
||||
obj_id = super(project_issue, self).create(cr, uid, vals, context=context)
|
||||
project_id = self.browse(cr, uid, obj_id, context=context).project_id
|
||||
name = False
|
||||
if project_id:
|
||||
for key in project_id.message_subtype_data:
|
||||
if key == 'New Task' and project_id.message_subtype_data[key]['default'] == True:
|
||||
name = 'created'
|
||||
if key == 'Task Closed' and project_id.message_subtype_data[key]['default'] == True:
|
||||
name = 'closed'
|
||||
subtype_ids = subtype_obj.search(cr, uid, [('res_model', '=', self._name), ('name', 'ilike', name)], context=context)
|
||||
subtype_obj.write(cr,uid, subtype_ids, {'default': project_id.message_subtype_data[key]['default']},context=context)
|
||||
followers = [follower.id for follower in project_id.message_follower_ids]
|
||||
self.message_subscribe(cr, uid, [obj_id], followers, subtype_ids= subtype_ids, context=context)
|
||||
|
||||
# subscribe project follower to the issue
|
||||
self._subscribe_project_followers_to_issue(cr, uid, obj_id, context=context)
|
||||
self.create_send_note(cr, uid, [obj_id], context=context)
|
||||
|
||||
return obj_id
|
||||
|
||||
# -------------------------------------------------------
|
||||
|
|
|
@ -44,17 +44,19 @@ Access all issues from the top Project menu, and access the issues of a specific
|
|||
|
||||
<!-- Mail subtypes -->
|
||||
<record id="mail.mt_issue_new" model="mail.message.subtype">
|
||||
<field name="name">created</field>
|
||||
<field name="name">New</field>
|
||||
<field name="res_model">project.issue</field>
|
||||
<field name="default" eval="False"/>
|
||||
</record>
|
||||
<record id="mail.mt_issue_new" model="mail.message.subtype">
|
||||
<field name="name">stage change</field>
|
||||
<field name="res_model">project.issue</field>
|
||||
<field name="default" eval="False"/>
|
||||
</record>
|
||||
<record id="mail.mt_issue_closed" model="mail.message.subtype">
|
||||
<field name="name">closed</field>
|
||||
<field name="name">Closed</field>
|
||||
<field name="res_model">project.issue</field>
|
||||
</record>
|
||||
<record id="mail.mt_issue_canceled" model="mail.message.subtype">
|
||||
<field name="name">Canceled</field>
|
||||
<field name="res_model">project.issue</field>
|
||||
</record>
|
||||
<record id="mail.mt_issue_change" model="mail.message.subtype">
|
||||
<field name="name">Stage Changed</field>
|
||||
<field name="res_model">project.issue</field>
|
||||
</record>
|
||||
|
||||
|
|
Loading…
Reference in New Issue