[IMP] mail: _get_message_data: display only number of new messages
authorChristophe Matthieu <chm@openerp.com>
Thu, 14 Feb 2013 14:34:17 +0000 (15:34 +0100)
committerChristophe Matthieu <chm@openerp.com>
Thu, 14 Feb 2013 14:34:17 +0000 (15:34 +0100)
bzr revid: chm@openerp.com-20130214143417-suf0tyonrewh2a7l

addons/mail/mail_thread.py
addons/project/project_view.xml
addons/project_issue/project_issue_view.xml

index 46052b0..03f681c 100644 (file)
@@ -35,6 +35,7 @@ from openerp import SUPERUSER_ID
 from openerp.addons.mail.mail_message import decode
 from openerp.osv import fields, osv
 from openerp.tools.safe_eval import safe_eval as eval
+from openerp.tools.translate import _
 
 _logger = logging.getLogger(__name__)
 
@@ -92,23 +93,21 @@ class mail_thread(osv.AbstractModel):
         """ Computes:
             - message_unread: has uid unread message for the document
             - message_summary: html snippet summarizing the Chatter for kanban views """
-        res = dict((id, dict(message_unread=False, message_summary='')) for id in ids)
+        res = dict((id, dict(message_unread=False, message_summary=' ')) for id in ids)
         user_pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0]
 
         # search for unread messages, directly in SQL to improve performances
-        cr.execute("""  SELECT m.res_id FROM mail_message m
+        cr.execute("""  SELECT m.res_id, COUNT(n.message_id) as nb FROM mail_message m
                         RIGHT JOIN mail_notification n
                         ON (n.message_id = m.id AND n.partner_id = %s AND (n.read = False or n.read IS NULL))
-                        WHERE m.model = %s AND m.res_id in %s""",
+                        WHERE m.model = %s AND m.res_id in %s
+                        GROUP BY m.res_id""",
                     (user_pid, self._name, tuple(ids),))
-        msg_ids = [result[0] for result in cr.fetchall()]
-        for msg_id in msg_ids:
-            res[msg_id]['message_unread'] = True
-
-        for thread in self.browse(cr, uid, ids, context=context):
-            cls = res[thread.id]['message_unread'] and ' class="oe_kanban_mail_new"' or ''
-            res[thread.id]['message_summary'] = "<span%s><span class='oe_e'>9</span> %d</span> <span><span class='oe_e'>+</span> %d</span>" % (cls, len(thread.message_ids), len(thread.message_follower_ids))
-
+        for result in cr.fetchall():
+            res[result[0]]['message_unread'] = True
+            if result[1]:
+                title = result[1] > 1 and _("There are %d messages unread") % result[1] or _("There is 1 message unread")
+                res[result[0]]['message_summary'] = "<span class='oe_kanban_mail_new' title='%s'><span class='oe_e'>9</span> %d %s</span>" % (title, result[1], _("New"))
         return res
 
     def _get_subscription_data(self, cr, uid, ids, name, args, context=None):
index b102c01..b49d61c 100644 (file)
                     <field name="remaining_hours" sum="Remaining Time" groups="project.group_time_work_estimation_tasks"/>
                     <field name="date_deadline"/>
                     <field name="message_summary"/>
-                    <field name="message_unread"/>
                     <field name="categ_ids"/>
                     <templates>
                     <t t-name="kanban-box">
                                     </span>
                                 </div>
                                 <div class="oe_kanban_footer_left" style="margin-top:5px;">
+                                    <t t-raw="record.message_summary.raw_value"/>
                                     <field name="categ_ids"/>
                                 </div>
                             </div>
index 7737545..60afb7a 100644 (file)
                     <field name="user_id"/>
                     <field name="date_deadline"/>
                     <field name="kanban_state"/>
+                    <field name="message_summary"/>
                     <templates>
                         <t t-name="kanban-tooltip">
                            <ul class="oe_kanban_tooltip">
                                             <img t-att-src="kanban_image('res.users', 'image_small', record.user_id.raw_value)" t-att-title="record.user_id.value" width="24" height="24" class="oe_kanban_avatar"/>
                                         </div>
                                     </div>
+                                    <div class="oe_kanban_footer_left">
+                                        <t t-raw="record.message_summary.raw_value"/>
+                                    </div>
                                 </div>
                                 <div class="oe_clear"></div>
                             </div>