我希望从我的Controller类内部获取用户的通知号

时间:2019-05-17 02:53:32

标签: odoo-9

我正在使用odoo 9,并且有一个控制器类。在控制器内部,我希望获得特定用户的通知号。就像上图一样,我希望得到4和2。谢谢

@api.multi
  def _get_message_unread(self):
      res = dict((res_id, 0) for res_id in self.ids)
      partner_id = self.env.user.partner_id.id

      # search for unread messages, directly in SQL to improve performances
      self._cr.execute(""" SELECT msg.res_id FROM mail_message msg
                           RIGHT JOIN mail_message_mail_channel_rel rel
                           ON rel.mail_message_id = msg.id
                           RIGHT JOIN mail_channel_partner cp
                           ON (cp.channel_id = rel.mail_channel_id AND cp.partner_id = %s AND
                              (cp.seen_message_id IS NULL OR cp.seen_message_id < msg.id))
                           WHERE msg.model = %s AND msg.res_id = ANY(%s) AND
                                 (msg.author_id IS NULL OR msg.author_id != %s) AND
                                 (msg.message_type != 'notification' OR msg.model != 'mail.channel')""",
                       (partner_id, self._name, list(self.ids), partner_id,))
      for result in self._cr.fetchall():
          res[result[0]] += 1

      for record in self:
          record.message_unread_counter = res.get(record.id, 0)
          record.message_unread = bool(record.message_unread_counter)

  ```

0 个答案:

没有答案