summaryrefslogtreecommitdiff
path: root/addons/project/project.py
diff options
context:
space:
mode:
authorOlivier Dony <odo@openerp.com>2012-07-03 18:01:55 +0200
committerOlivier Dony <odo@openerp.com>2012-07-03 18:01:55 +0200
commitf66753362b5d83ba0bef5cb7da2be8d257e5fbb3 (patch)
tree74a1a9244693ea1ce0ffb7b90f8e1c754e5af1dd /addons/project/project.py
parent234118ddb76f6d72a773fd5dda086522aba3ae6a (diff)
parent790f64cca643d6ef2a259c56552a3b17895f3b87 (diff)
[MERGE] Implementation of mail.alias by Jigar Amin
bzr revid: odo@openerp.com-20120703160155-gw8po01vmm0q30ow
Diffstat (limited to 'addons/project/project.py')
-rw-r--r--addons/project/project.py52
1 files changed, 47 insertions, 5 deletions
diff --git a/addons/project/project.py b/addons/project/project.py
index ab02cc870bb..aa32fbb16e2 100644
--- a/addons/project/project.py
+++ b/addons/project/project.py
@@ -55,7 +55,7 @@ class project_task_type(osv.osv):
class project(osv.osv):
_name = "project.project"
_description = "Project"
- _inherits = {'account.analytic.account': "analytic_account_id"}
+ _inherits = {'account.analytic.account': "analytic_account_id","mail.alias":"alias_id"}
_inherit = ['ir.needaction_mixin', 'mail.thread']
def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False):
@@ -164,6 +164,8 @@ class project(osv.osv):
for task in self.pool.get('project.task').browse(cr, uid, task_ids, context):
res[task.project_id.id] += 1
return res
+ def _get_alias_model(self, cr, uid, context=None):
+ return [('model_project_task', "Tasks")]
def _get_followers(self, cr, uid, ids, name, arg, context=None):
'''
@@ -215,12 +217,13 @@ class project(osv.osv):
'type_ids': fields.many2many('project.task.type', 'project_task_type_rel', 'project_id', 'type_id', 'Tasks Stages', states={'close':[('readonly',True)], 'cancelled':[('readonly',True)]}),
'task_count': fields.function(_task_count, type='integer', string="Open Tasks"),
'color': fields.integer('Color Index'),
+ 'alias_id': fields.many2one('mail.alias', 'Mail Alias', ondelete="cascade", required=True),
+ 'alias_model': fields.selection(_get_alias_model, "Alias Model",select="1", required=True),
'privacy_visibility': fields.selection([('public','Public'), ('followers','Followers Only')], 'Privacy / Visibility'),
'state': fields.selection([('template', 'Template'),('draft','New'),('open','In Progress'), ('cancelled', 'Cancelled'),('pending','Pending'),('close','Closed')], 'Status', required=True,),
'followers': fields.function(_get_followers, method=True, fnct_search=_search_followers,
type='many2many', relation='res.users', string='Followers'),
}
-
def dummy(self, cr, uid, ids, context):
return True
@@ -236,6 +239,7 @@ class project(osv.osv):
'priority': 1,
'sequence': 10,
'type_ids': _get_type_common,
+ 'alias_model':'model_project_task',
}
# TODO: Why not using a SQL contraints ?
@@ -250,6 +254,26 @@ class project(osv.osv):
(_check_dates, 'Error! project start-date must be lower then project end-date.', ['date_start', 'date'])
]
+ def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
+ res = super(project,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
+ if view_type == 'form' or view_type == 'kanban':
+ domain = self.pool.get("ir.config_parameter").get_param(cr, uid, "mail.catchall.domain", context=context)
+ if not domain:
+ doc = etree.XML(res['arch'])
+ alias_node = doc.xpath("//field[@name='alias_id']")[0]
+ parent = alias_node.getparent()
+ parent.remove(alias_node)
+ if view_type == "form":
+ model_node = doc.xpath("//field[@name='alias_model']")[0]
+ parent = model_node.getparent()
+ parent.remove(model_node)
+ else:
+ model_node = doc.xpath("//field[@name='alias_id']")[0]
+ parent = model_node.getparent()
+ parent.remove(model_node)
+ res['arch'] = etree.tostring(doc)
+ return res
+
def set_template(self, cr, uid, ids, context=None):
res = self.setActive(cr, uid, ids, value=False, context=context)
return res
@@ -497,9 +521,17 @@ def Project():
return self.pool.get('res.users').read(cr, uid, sub_ids, context=context)
def create(self, cr, uid, vals, context=None):
- obj_id = super(project, self).create(cr, uid, vals, context=context)
- self.create_send_note(cr, uid, [obj_id], context=context)
- return obj_id
+ model_pool = self.pool.get('ir.model.data')
+ alias_pool = self.pool.get('mail.alias')
+ model, res_id = model_pool.get_object_reference( cr, uid, "project", vals.get('alias_model','model_project_task'))
+ vals.update({'alias_name':"project",
+ 'alias_model_id': res_id})
+ alias_pool.create_unique_alias(cr, uid, vals, context=context)
+ res = super( project, self).create(cr, uid, vals, context)
+ record = self.read(cr, uid, res, context)
+ alias_pool.write(cr, uid, [record['alias_id']], {'alias_defaults':{'project_id': record['id']}}, context)
+ self.create_send_note(cr, uid, [res], context=context)
+ return res
def create_send_note(self, cr, uid, ids, context=None):
return self.message_append_note(cr, uid, ids, body=_("Project has been <b>created</b>."), context=context)
@@ -520,6 +552,16 @@ def Project():
message = _("Project has been <b>closed</b>.")
return self.message_append_note(cr, uid, ids, body=message, context=context)
+ def write(self, cr, uid, ids, vals, context=None):
+ model_pool = self.pool.get('ir.model.data')
+ alias_pool = self.pool.get('mail.alias')
+ # if alias_model have been changed then change alias_model_id of alias also.
+ if vals.get('alias_model'):
+ model, res_id = model_pool.get_object_reference( cr, uid, "project", vals.get('alias_model','model_project_task'))
+ alias_id = self.browse(cr, uid, ids[0], context).alias_id
+ alias_pool.write(cr, uid, [alias_id.id], {'alias_model_id': res_id}, context=context)
+ return super(project, self).write(cr, uid, ids, vals, context=context)
+
class task(base_stage, osv.osv):
_name = "project.task"