Skip to Content
Menu
This question has been flagged
1 Reply
4942 Views

I'm using odoo version 12 and i have a module that inherit maintenace module :

class iserp_op_asset_request(models.Model):

    _inherit ="maintenance.request" 

    ...


The maintenance module have function to automatically add a user as followers :

@api.model    

def create(self, vals): 

   self = self.with_context(mail_create_nolog=True)        

   request = super(MaintenanceRequest, self).create(vals) 

   if request.owner_user_id or request.user_id:            

      request._add_followers()       

   if request.equipment_id and not request.maintenance_team_id:            

      request.maintenance_team_id = request.equipment_id.maintenance_team_id       

    request.activity_update()        

    return request 

def _add_followers(self): 

   for request in self:   

      partner_ids = (request.owner_user_id.partner_id + request.user_id.partner_id).ids           

      request.message_subscribe(partner_ids=partner_ids)


So, i wanna automatically add the users who's in Administrative Manager groups as followers when the record be create. I modified _add_followers like this:

def _add_followers(self): 

   for request in self: 

      user_ids = self.env['res.groups'].search([('name', '=', 'Administrative Manager')]).users.id

      request.message_subscribe(partner_ids=user_ids) 


A Error display when i try create a new record

 File "/usr/lib/python3/dist-packages/odoo/addons/maintenance/models/maintenance.py", line 337, in create
    request._add_followers()
  File "/mnt/extra-addons/iserp_op_asset/models/iserp_op_asset_request.py", line 17, in _add_followers
    user_ids = self.env['res.groups'].search([('name', '=', 'Administrative Manager')]).users.id
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 2863, in __get__
    raise ValueError("Expected singleton: %s" % record)
ValueError: Expected singleton: res.users(8, 6)

What am i wrong here ? and how can i fix that ?


Avatar
Discard
Best Answer

Hi,

It is a Singleton Error.

Change this line

user_ids = self.env['res.groups'].search([('name', '=', 'Administrative Manager')]).users.id

Into

user_ids = self.env['res.groups'].search([('name', '=', 'Administrative Manager')]).users.ids

Note:
Searching with name is not a good practice. 
You can use external ID instead,if it match with your requirement

Thanks & Regards
Avinash N K
Avatar
Discard
Author

Thank you so much !!!

Related Posts Replies Views Activity
2
Jul 23
1219
5
Feb 20
8020
1
Mar 16
3293
4
Mar 24
297
0
Feb 24
189