[FIX] mail: default_starred key is recognized when creating a mail_message, handled in mail_messgae.create() to avoid issues with notifications if using an invert function on starred function field.

bzr revid: tde@openerp.com-20121130104038-3nivz6kvdyi22f3l
This commit is contained in:
Thibault Delavallée 2012-11-30 11:40:38 +01:00
parent e098e2c9c3
commit 91cb411e80
3 changed files with 15 additions and 4 deletions

View File

@ -641,7 +641,6 @@ Andrew</field>
<field name="type">comment</field>
<field name="subtype_id" ref="mail.mt_comment"/>
<field name="author_id" ref="base.res_partner_4"/>
<field name="favorite_user_ids" eval="[(6, 0, [ref('base.user_root')])]"/>
</record>
<record id="msg_case18_2" model="mail.message">
<field name="model">crm.lead</field>
@ -651,7 +650,6 @@ Andrew</field>
<field name="subtype_id" ref="mail.mt_comment"/>
<field name="parent_id" ref="msg_case18_1"/>
<field name="author_id" ref="base.partner_demo"/>
<field name="favorite_user_ids" eval="[(6, 0, [ref('base.user_root')])]"/>
</record>
<record id="msg_case1_1" model="mail.message">
<field name="subject">Inquiry</field>
@ -669,6 +667,9 @@ Andrew</field>
<field name="body">Want to know features and benefits to use the new software.</field>
<field name="type">comment</field>
</record>
<function model="mail.message" name="set_message_starred"
eval="[ ref('msg_case18_1'), ref('msg_case18_2')], True, {}"
/>
</data>
</openerp>

View File

@ -682,12 +682,23 @@ class mail_message(osv.Model):
(self._description, operation))
def create(self, cr, uid, values, context=None):
if context is None:
context = {}
default_starred = context.pop('default_starred', False)
if not values.get('message_id') and values.get('res_id') and values.get('model'):
values['message_id'] = tools.generate_tracking_message_id('%(res_id)s-%(model)s' % values)
elif not values.get('message_id'):
values['message_id'] = tools.generate_tracking_message_id('private')
newid = super(mail_message, self).create(cr, uid, values, context)
self._notify(cr, SUPERUSER_ID, newid, context=context)
# TDE FIXME: handle default_starred. Why not setting an inv on starred ?
# Because starred will call set_message_starred, that looks for notifications.
# When creating a new mail_message, it will create a notification to a message
# that does not exist, leading to an error (key not existing). Also this
# this means unread notifications will be created, yet we can not assure
# this is what we want.
if default_starred:
self.set_message_starred(cr, uid, [newid], True, context=context)
return newid
def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):

View File

@ -990,8 +990,7 @@ openerp.mail = function (session) {
// add message composition form view
if (!this.compose_message) {
this.compose_message = new mail.ThreadComposeMessage(this, this, {
// TDE FIXME: default_favorite_user_ids does not exist anymore -> you should create the message, set starred then update
'context': this.options.compose_as_todo && !this.thread_level ? this.context : this.context,
'context': this.options.compose_as_todo && !this.thread_level ? _.extend(this.context, { 'default_starred': true }) : this.context,
'options': this.options,
});
if (!this.thread_level || this.thread_level > this.options.display_indented_thread) {