[FIX] mail: mail_message from field renamed to email_from, because of reserved word. Various fixes.
bzr revid: tde@openerp.com-20121025135020-83h1cybp6um53uq5
This commit is contained in:
parent
e261dd977e
commit
82398c12c8
|
@ -46,7 +46,7 @@ class mail_message(osv.Model):
|
|||
_order = 'id desc'
|
||||
|
||||
_message_read_limit = 10
|
||||
_message_read_fields = ['id', 'parent_id', 'model', 'res_id', 'body', 'subject', 'date', 'to_read',
|
||||
_message_read_fields = ['id', 'parent_id', 'model', 'res_id', 'body', 'subject', 'date', 'to_read', 'email_from',
|
||||
'type', 'vote_user_ids', 'attachment_ids', 'author_id', 'partner_ids', 'record_name', 'favorite_user_ids']
|
||||
_message_record_name_length = 18
|
||||
_message_read_more_limit = 1024
|
||||
|
@ -115,7 +115,7 @@ class mail_message(osv.Model):
|
|||
], 'Type',
|
||||
help="Message type: email for email message, notification for system "\
|
||||
"message, comment for other messages such as user replies"),
|
||||
'from': fields.char('From',
|
||||
'email_from': fields.char('From',
|
||||
help="Email address of the sender, to use if it does not match any partner."),
|
||||
'author_id': fields.many2one('res.partner', 'Author',
|
||||
help="Partner that did write the message. If not set, try to use the From field instead."),
|
||||
|
@ -207,8 +207,8 @@ class mail_message(osv.Model):
|
|||
if message['author_id']:
|
||||
is_author = message['author_id'][0] == self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=None)['partner_id'][0]
|
||||
author_id = message['author_id']
|
||||
elif message['from']:
|
||||
author_id = (0, message['from'])
|
||||
elif message['email_from']:
|
||||
author_id = (0, message['email_from'])
|
||||
|
||||
has_voted = False
|
||||
if uid in message.get('vote_user_ids'):
|
||||
|
@ -397,9 +397,11 @@ class mail_message(osv.Model):
|
|||
if ids is None:
|
||||
ids = self.search(cr, uid, domain, context=context, limit=limit)
|
||||
for message in self.read(cr, uid, ids, self._message_read_fields, context=context):
|
||||
message_id = message['id']
|
||||
|
||||
# if not in tree and not in message_loaded list
|
||||
if not read_messages.get(message.get('id')) and message.get('id') not in message_unload_ids:
|
||||
read_messages[message.get('id')] = message
|
||||
if not message_id in read_messages and not message_id in message_unload_ids:
|
||||
read_messages[message_id] = message
|
||||
message_list.append(self._message_get_dict(cr, uid, message, context=context))
|
||||
|
||||
# get the older ancestor the user can read, update its ancestor field
|
||||
|
@ -412,8 +414,8 @@ class mail_message(osv.Model):
|
|||
message = parent
|
||||
parent = self._get_parent(cr, uid, message, context=context)
|
||||
# if in thread: add its ancestor to the list of messages
|
||||
if not read_messages.get(message.get('id')) and message.get('id') not in message_unload_ids:
|
||||
read_messages[message.get('id')] = message
|
||||
if not message['id'] in read_messages and not message['id'] in message_unload_ids:
|
||||
read_messages[message['id']] = message
|
||||
message_list.append(self._message_get_dict(cr, uid, message, context=context))
|
||||
|
||||
# get the child expandable messages for the tree
|
||||
|
@ -645,11 +647,12 @@ class mail_message(osv.Model):
|
|||
], context=context)
|
||||
fol_objs = fol_obj.read(cr, uid, fol_ids, ['partner_id'], context=context)
|
||||
partners_to_notify |= set(fol['partner_id'][0] for fol in fol_objs)
|
||||
# add myself if I wrote on my wall, otherwise remove myself author
|
||||
# when writing to a wall
|
||||
if message.get('author_id') and message.get('model') == "res.partner" and message.get('res_id') == message.get('author_id')[0]:
|
||||
partners_to_notify |= set([message.get('author_id')[0]])
|
||||
else:
|
||||
elif message.get('author_id'):
|
||||
partners_to_notify = partners_to_notify - set([message.get('author_id')[0]])
|
||||
|
||||
if partners_to_notify:
|
||||
self.write(cr, SUPERUSER_ID, [newid], {'notified_partner_ids': [(4, p_id) for p_id in partners_to_notify]}, context=context)
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
<group>
|
||||
<field name="subject"/>
|
||||
<field name="author_id"/>
|
||||
<field name="email_from"/>
|
||||
<field name="date"/>
|
||||
<field name="type"/>
|
||||
<field name="subtype_id"/>
|
||||
|
@ -38,6 +39,7 @@
|
|||
<field name="res_id"/>
|
||||
<field name="parent_id"/>
|
||||
<field name="partner_ids" widget="many2many_tags"/>
|
||||
<field name="notified_partner_ids" widget="many2many_tags"/>
|
||||
</group>
|
||||
</group>
|
||||
<field name="body"/>
|
||||
|
|
|
@ -557,6 +557,7 @@ class mail_thread(osv.AbstractModel):
|
|||
msg_dict = {
|
||||
'type': 'email',
|
||||
'subtype': 'mail.mt_comment',
|
||||
'author_id': False,
|
||||
}
|
||||
if not isinstance(message, Message):
|
||||
if isinstance(message, unicode):
|
||||
|
@ -575,7 +576,7 @@ class mail_thread(osv.AbstractModel):
|
|||
if 'Subject' in message:
|
||||
msg_dict['subject'] = decode(message.get('Subject'))
|
||||
|
||||
# Envelope fields not stored in mail.message but made available for message_new()
|
||||
# Envelope fields not stored in mail.message but made available for message_new()
|
||||
msg_dict['from'] = decode(message.get('from'))
|
||||
msg_dict['to'] = decode(message.get('to'))
|
||||
msg_dict['cc'] = decode(message.get('cc'))
|
||||
|
@ -585,7 +586,7 @@ class mail_thread(osv.AbstractModel):
|
|||
if author_ids:
|
||||
msg_dict['author_id'] = author_ids[0]
|
||||
else:
|
||||
msg_dict['from'] = message.get('from')
|
||||
msg_dict['email_from'] = message.get('from')
|
||||
partner_ids = self._message_find_partners(cr, uid, message, ['From', 'To', 'Cc'], context=context)
|
||||
msg_dict['partner_ids'] = partner_ids
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ class test_mail(TestMailMockups):
|
|||
group_employee_id = group_employee_ref and group_employee_ref[1] or False
|
||||
# Test users
|
||||
self.user_raoul_id = self.res_users.create(cr, uid,
|
||||
{'name': 'Raoul Grosbedon', 'login': 'raoul', 'groups_id': [(6, 0, [group_employee_id])]})
|
||||
{'name': 'Raoul Grosbedon', 'email': 'raoul@raoul.fr', 'login': 'raoul', 'groups_id': [(6, 0, [group_employee_id])]})
|
||||
self.user_raoul = self.res_users.browse(cr, uid, self.user_raoul_id)
|
||||
self.user_admin = self.res_users.browse(cr, uid, uid)
|
||||
|
||||
|
@ -167,7 +167,7 @@ class test_mail(TestMailMockups):
|
|||
|
||||
def test_00_message_process(self):
|
||||
""" Testing incoming emails processing. """
|
||||
cr, uid = self.cr, self.uid
|
||||
cr, uid, user_raoul = self.cr, self.uid, self.user_raoul
|
||||
# Incoming mail creates a new mail_group "frogs"
|
||||
self.assertEqual(self.mail_group.search(cr, uid, [('name', '=', 'frogs')]), [])
|
||||
mail_frogs = MAIL_TEMPLATE.format(to='groups@example.com, other@gmail.com', subject='frogs', extra='')
|
||||
|
@ -205,6 +205,26 @@ class test_mail(TestMailMockups):
|
|||
self.assertEqual(new_mail.body, '\n<pre>\nPlease call me as soon as possible this afternoon!\n\n--\nSylvie\n</pre>\n',
|
||||
'plaintext mail incorrectly parsed')
|
||||
|
||||
# Do: post a new message, with a known partner
|
||||
test_msg_id = '<deadcafe.1337-2@smtp.agrolait.com>'
|
||||
TEMPLATE_MOD = MAIL_TEMPLATE_PLAINTEXT.replace('Sylvie Lelitre <sylvie.lelitre@agrolait.com>', user_raoul.email)
|
||||
mail_new = TEMPLATE_MOD.format(to='Friendly Frogs <group+frogs@example.com>', subject='extra news', extra='', msg_id=test_msg_id)
|
||||
self.mail_thread.message_process(cr, uid, None, mail_new)
|
||||
new_mail = self.mail_message.browse(cr, uid, self.mail_message.search(cr, uid, [('message_id', '=', test_msg_id)])[0])
|
||||
# Test: author_id set, not email_from
|
||||
self.assertEqual(new_mail.author_id, user_raoul.partner_id, 'message process wrong author found')
|
||||
self.assertFalse(new_mail.email_from, 'message process should not set the email_from when an author is found')
|
||||
|
||||
# Do: post a new message, with a unknown partner
|
||||
test_msg_id = '<deadcafe.1337-3@smtp.agrolait.com>'
|
||||
TEMPLATE_MOD = MAIL_TEMPLATE_PLAINTEXT.replace('Sylvie Lelitre <sylvie.lelitre@agrolait.com>', '_abcd_')
|
||||
mail_new = TEMPLATE_MOD.format(to='Friendly Frogs <group+frogs@example.com>', subject='super news', extra='', msg_id=test_msg_id)
|
||||
self.mail_thread.message_process(cr, uid, None, mail_new)
|
||||
new_mail = self.mail_message.browse(cr, uid, self.mail_message.search(cr, uid, [('message_id', '=', test_msg_id)])[0])
|
||||
# Test: author_id set, not email_from
|
||||
self.assertFalse(new_mail.author_id, 'message process shnould not have found a partner for _abcd_ email address')
|
||||
self.assertIn('_abcd_', new_mail.email_from, 'message process should set en email_from when not finding a partner_id')
|
||||
|
||||
def test_10_followers_function_field(self):
|
||||
""" Tests designed for the many2many function field 'follower_ids'.
|
||||
We will test to perform writes using the many2many commands 0, 3, 4,
|
||||
|
|
Loading…
Reference in New Issue