Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
6024 Переглядів

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 ?


Аватар
Відмінити
Найкраща відповідь

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
Аватар
Відмінити
Автор

Thank you so much !!!

Related Posts Відповіді Переглядів Дія
2
лип. 23
2345
5
лют. 20
9057
1
бер. 16
4135
4
бер. 24
1614
0
лют. 24
1115