From dec8de9aed5826c0bde26ccd28c8fe23bed1eb49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 27 Mar 2012 09:30:53 +0200 Subject: [PATCH] [IMP] Added a function field to the message, holdind the record name. bzr revid: tde@openerp.com-20120327073053-hiabrfs80duu8j6i --- addons/mail/mail_message.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 63a2ec971e5..bc71edac450 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -69,6 +69,17 @@ class mail_message_common(osv.osv_memory): database model or wizard screen that needs to hold a kind of message""" + def get_record_name(self, cr, uid, ids, name, arg, context=None): + if context is None: + context = {} + result = dict.fromkeys(ids, '') + for message in self.browse(cr, uid, ids, context=context): + if not message.model or not message.res_id: + continue + model = self.pool.get(message.model) + result[message.id] = model.name_get(cr, uid, [message.res_id], context=context)[0][1] + return result + _name = 'mail.message.common' _rec_name = 'subject' _columns = { @@ -91,9 +102,16 @@ class mail_message_common(osv.osv_memory): 'body_text': fields.text('Text contents', help="Plain-text version of the message"), 'body_html': fields.text('Rich-text contents', help="Rich-text/HTML version of the message"), 'parent_id': fields.many2one('mail.message', 'Parent message', help="Parent message, used for displaying as threads with hierarchy"), + 'type': fields.selection([ + ('email', 'e-mail'), + ('comment', 'Comment'), + ('notification', 'System notification'), + ], 'Type', help="Message type: e-mail for e-mail message, notification for system message, comment for other messages such as user replies"), + 'record_name': fields.function(get_record_name, type='string', help="Name of the record, matching the result of the name_get."), } _defaults = { + 'type': 'comment', 'subtype': 'plain', 'date': (lambda *a: fields.datetime.now()), } @@ -182,17 +200,11 @@ class mail_message(osv.osv): ], 'State', readonly=True), 'auto_delete': fields.boolean('Auto Delete', help="Permanently delete this email after sending it, to save space"), 'original': fields.binary('Original', help="Original version of the message, as it was sent on the network", readonly=1), - 'type': fields.selection([ - ('email', 'e-mail'), - ('comment', 'Comment'), - ('notification', 'System notification'), - ], 'Type', help="Message type: e-mail for e-mail message, notification for system message, comment for other messages such as user replies"), } _defaults = { 'state': 'received', - 'type': 'comment', } #------------------------------------------------------