Skip to content
  • Categories
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse

Odoo 中文社区

  1. Home
  2. Categories
  3. Odoo 开发与实施交流
  4. [已解决] 获取Followers的User id

[已解决] 获取Followers的User id

Scheduled Pinned Locked Moved Odoo 开发与实施交流
4 Posts 2 Posters 2.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H
    H
    hui
    wrote on last edited by hui
    #1

    获取当前单据的Followers的id,使用self的什么属性直接可以获取到。

    H 1 Reply Last reply
    0
    • H hui

      获取当前单据的Followers的id,使用self的什么属性直接可以获取到。

      H
      H
      hui
      wrote on last edited by hui
      #2

      @hui
      获取mail.follower对象self.message_follower_ids
      或者下面的也是获取的mail.follower对象

      followers = self.env['mail.followers'].sudo().search([
                  ('res_model', '=', self._name),
                  ('res_id', '=', self.id)])
      

      但是followers并不一定是users。

      疑问:不知道mail.follower中的partner_id是什么作用,这个res_id应该是当前单据的id吧。

      获取Followers中的User 好像没有一步到位的方法,官方也没有提供对应的方法或者属性可用。只能自己写了:

      follower_partner_ids = self.message_follower_ids.mapped('partner_id').ids
              for partner_id in follower_partner_ids:
                  if partner_id:
                      follower_users_ids = self.env['res.users'].search([('partner_id', '=', partner_id)]).ids
                      
      
      1 Reply Last reply
      1
      • JoshuaJ
        JoshuaJ
        Joshua
        管理员
        wrote on last edited by
        #3
            # Note. There is no integrity check on model names for performance reasons.
            # However, followers of unlinked models are deleted by models themselves
            # (see 'ir.model' inheritance).
            res_model = fields.Char(
                'Related Document Model Name', required=True, index=True)
            res_id = fields.Integer(
                'Related Document ID', index=True, help='Id of the followed resource')
            partner_id = fields.Many2one(
                'res.partner', string='Related Partner', ondelete='cascade', index=True)
            channel_id = fields.Many2one(
                'mail.channel', string='Listener', ondelete='cascade', index=True)
            subtype_ids = fields.Many2many(
                'mail.message.subtype', string='Subtype',
                help="Message subtypes followed, meaning subtypes that will be pushed onto the user's Wall.")
        

        mail.follower关联res.partner,因为关注者不一定是系统的登录用户,他们只需要通过邮件收到对应的信息就可以了。
        res_id 就是关联的单据id。
        res_model是关联的单据模型。

        【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

        H 1 Reply Last reply
        0
        • JoshuaJ Joshua
              # Note. There is no integrity check on model names for performance reasons.
              # However, followers of unlinked models are deleted by models themselves
              # (see 'ir.model' inheritance).
              res_model = fields.Char(
                  'Related Document Model Name', required=True, index=True)
              res_id = fields.Integer(
                  'Related Document ID', index=True, help='Id of the followed resource')
              partner_id = fields.Many2one(
                  'res.partner', string='Related Partner', ondelete='cascade', index=True)
              channel_id = fields.Many2one(
                  'mail.channel', string='Listener', ondelete='cascade', index=True)
              subtype_ids = fields.Many2many(
                  'mail.message.subtype', string='Subtype',
                  help="Message subtypes followed, meaning subtypes that will be pushed onto the user's Wall.")
          

          mail.follower关联res.partner,因为关注者不一定是系统的登录用户,他们只需要通过邮件收到对应的信息就可以了。
          res_id 就是关联的单据id。
          res_model是关联的单据模型。

          H
          H
          hui
          wrote on last edited by
          #4

          @joshua
          懂了,谢谢。实际应该从我写的例子里面就可以看出来啦。

          1 Reply Last reply
          0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Tags
          • Popular
          • Users
          • Groups