I want to retrieve users according to a number of criteria. I can execute the following request with odoo-bin and I have the users I want to retrieve.
my query:
self.env['res.users'].sudo().search([('id','in',[k.name_student_id.id for k in self.env['rdv.rdv'].sudo().search([('nb_rdv','>=',1)])])]).ids
the query returns a list of ids. But when I put the same query in the many2one field, I get all users. I just don't think the request is being executed.
my query in field:
name_student_id = fields.Many2one('res.users', 'Etudiant', required=True, default=lambda self: self.env['res.users'].sudo().search([('id','in',[k.name_student_id.id for k in self.env['rdv.rdv'].sudo().search([('nb_rdv','>=',1)])])]).ids )
My query must be like this:
name_student_id = fields.Many2one('res.users', 'Etudiant', required=True, default=lambda self: self.env['res.users'].sudo().search([('id','in','[43,64,65]')]) )
I need help and would like to know if there is not another method to execute the query and display the result in the many2one field to display the users. Thanks
Default is used to set a value on your field, the method is expected to return a valid value for your many2one witch is int
, to define a default domain use domain attribute not default, the method is expected to return a valid domain not list of ids that domain will be passed when ever you do a search in your field:
domain=lambda self: [('id', 'in', self.env['rdv.rdv'].sudo().search([('nb_rdv','>=',1)]).mapped('name_student_id').ids)]