[ADD] mail module: added an update of ir_needaction model, to include the message_thread_read field in need_action. This will allow to remove most of the needaction definitions through various modules.

bzr revid: tde@openerp.com-20120607151753-j3znrs1jy5tx4xoh
This commit is contained in:
Thibault Delavallée
2012-06-07 17:17:53 +02:00
parent dc869082d3
commit de2e979212
3 changed files with 29 additions and 11 deletions
-7
View File
@@ -259,13 +259,6 @@ class crm_lead(base_stage, osv.osv):
'color': 0,
}
def get_needaction_user_ids(self, cr, uid, ids, context=None):
result = dict.fromkeys(ids, [])
for obj in self.browse(cr, uid, ids, context=context):
if obj.message_thread_read == False and obj.user_id:
result[obj.id] = [obj.user_id.id]
return result
def create(self, cr, uid, vals, context=None):
obj_id = super(crm_lead, self).create(cr, uid, vals, context)
self.create_send_note(cr, uid, [obj_id], context=context)
+1 -1
View File
@@ -171,7 +171,6 @@
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Leads" fonts="bold:needaction_pending==True" colors="blue:state=='pending';grey:state in ('cancel', 'done')">
<field name="needaction_pending" invisible="1"/>
<field name="date_deadline" invisible="1"/>
<field name="create_date" groups="base.group_no_one"/>
<field name="name"/>
@@ -187,6 +186,7 @@
<field name="referred" invisible="1"/>
<field name="channel_id" invisible="1"/>
<field name="subjects" invisible="1"/>
<field name="needaction_pending" invisible="1"/>
</tree>
</field>
</record>
+28 -3
View File
@@ -170,6 +170,9 @@ class mail_thread(osv.Model):
# create message
msg_id = message_obj.create(cr, uid, vals, context=context)
# Set as unread if writer is not the document responsible
#model_pool.message_mark_as_unread(cr, uid, [res_id], context=context)
# special: if install mode, do not push demo data
if context.get('install_mode', False):
return True
@@ -539,8 +542,6 @@ class mail_thread(osv.Model):
res_id = int(create_record(msg))
# To forward the email to other followers
self.message_forward(cr, uid, model, [res_id], msg_txt, context=context)
# Set as Unread
model_pool.message_mark_as_unread(cr, uid, [res_id], context=context)
return res_id
def message_new(self, cr, uid, msg_dict, custom_values=None, context=None):
@@ -833,12 +834,36 @@ class mail_thread(osv.Model):
#------------------------------------------------------
# Thread_state
#------------------------------------------------------
def message_mark_as_read(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'message_thread_read': True}, context=context)
def message_create_mark_as_unread(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids, context=context):
if hasattr(obj, 'user_id') and (not obj.user_id or (obj.user_id and obj.user_id.id != uid)):
self.mark_as_unread(cr, uid, [obj.id], context=None)
def message_mark_as_unread(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'message_thread_read': False}, context=context)
class ir_needaction_mixin(osv.Model):
""" Update of res.users class
- add a preference about sending emails about notificatoins
- make a new user follow itself
"""
_name = 'ir.needaction_mixin'
_inherit = ['ir.needaction_mixin']
def get_needaction_user_ids(self, cr, uid, ids, context=None):
""" Returns the user_ids that have to perform an action
:return: dict { record_id: [user_ids], }
"""
result = super(ir_needaction_mixin, self).get_needaction_user_ids(cr, uid, ids, context=context)
for obj in self.browse(cr, uid, ids, context=context):
if obj.message_thread_read == False and obj.user_id:
result[obj.id].add(obj.user_id.id)
return result
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: