[IMP]: Add subtype to task and issue from project.

bzr revid: atp@tinyerp.com-20121003135828-cblz52ewh2lyc2ta
This commit is contained in:
Atul Patel (OpenERP) 2012-10-03 19:28:28 +05:30
commit 307b705a9f
2 changed files with 26 additions and 2 deletions

View File

@ -1097,9 +1097,16 @@ 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)
task_record = self.browse(cr, uid, task_id, context=context)
project_obj = self.pool.get("project.project")
subtype_obj = self.pool.get('mail.message.subtype')
if task_record.project_id:
project_subtype = task_record.project_id.message_subtype_data
for key in project_subtype:
subtype_ids = subtype_obj.search(cr, uid, [('res_model', '=', self._name), ('name', 'ilike', key)], context=context)
if subtype_ids:
subtype_obj.write(cr,uid, subtype_ids, {'default': project_subtype[key]['default']},context=context)
project_follower_ids = [follower.id for follower in task_record.project_id.message_follower_ids]
self.message_subscribe(cr, uid, [task_id], project_follower_ids,
self.message_subscribe(cr, uid, [task_id], project_follower_ids,
context=context)
self._store_history(cr, uid, [task_id], context=context)
self.create_send_note(cr, uid, [task_id], context=context)
@ -1110,9 +1117,15 @@ class task(base_stage, osv.osv):
def write(self, cr, uid, ids, vals, context=None):
if isinstance(ids, (int, long)):
ids = [ids]
project_obj = self.pool.get("project.project")
subtype_obj = self.pool.get('mail.message.subtype')
if vals.get('project_id'):
project_id = self.pool.get('project.project').browse(cr, uid, vals.get('project_id'), context=context)
project_id = project_obj.browse(cr, uid, vals.get('project_id'), context=context)
vals['message_follower_ids'] = [(4, follower.id) for follower in project_id.message_follower_ids]
for key in project_id.message_subtype_data:
subtype_ids = subtype_obj.search(cr, uid, [('res_model', '=', self._name), ('name', '=', key)], context=context)
if subtype_ids:
subtype_obj.write(cr,uid, subtype_ids, {'default': project_id.message_subtype_data[key]['default']},context=context)
if vals and not 'kanban_state' in vals and 'stage_id' in vals:
new_stage = vals.get('stage_id')
vals_reset_kstate = dict(vals, kanban_state='normal')

View File

@ -362,10 +362,15 @@ class project_issue(base_stage, osv.osv):
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')
if any([field in vals for field in logged_fields]):
vals['date_action_last'] = time.strftime('%Y-%m-%d %H:%M:%S')
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:
subtype_ids = subtype_obj.search(cr, uid, [('res_model', '=', self._name), ('name', '=', key)], context=context)
if subtype_ids:
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]
return super(project_issue, self).write(cr, uid, ids, vals, context)
@ -384,8 +389,14 @@ 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
project_subtype = project_id.message_subtype_data
for key in project_subtype:
subtype_ids = subtype_obj.search(cr, uid, [('res_model', '=', self._name), ('name', 'ilike', key)], context=context)
if subtype_ids:
subtype_obj.write(cr,uid, subtype_ids, {'default': project_subtype[key]['default']},context=context)
if project_id:
followers = [follower.id for follower in project_id.message_follower_ids]
self.message_subscribe(cr, uid, [obj_id], followers, context=context)