# HELLO GUYS, I NEED HELP PLEASE!
# THESE ARE MY CODE AND THE ERROR
# I THINK THE ERROR COME FROM THE SYNTAX of LINE 14 (x.employe_ids = self.env...) in 'gestion.formation'
class gestion_formation(models.Model):
_name = 'gestion.formation'
fonction_ids = fields.Many2many (comodel_name='gestion.fonction')
employe_ids = fields.Many2many (comodel_name = 'gestion.employe', compute = '_employe_ids')
@api.onchange('employe_ids')
def _employe_ids(self):
for x in self:
x.employe_ids = self.env['gestion.employe'].search([('fonction_id.nom_fonction', '=', 'x.fonction_ids.nom_fonction')])
class gestion_fonction(models.Model):
_name = 'gestion.fonction'
nom_fonction = fields.Char ()
employe_ids = fields.One2many (comodel_name = 'gestion.employe', inverse_name = 'fonction_id')
formation_ids = fields.Many2many (comodel_name = 'gestion.formation')
class gestion_employe(models.Model):
_name = 'gestion.employe'
nom_employe = fields.Char ()
matricule = fields.Char ()
fonction_id = fields.Many2one (comodel_name = 'gestion.fonction')
formation_ids = fields.Many2many (comodel_name = 'gestion.formation')
##### ERROR #####
... ... ...
x.employe_ids = self.env['gestion.employe'].search([('fonction_id.nom_fonction', '=', x.fonction_ids.nom_fonction)])
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 947, in __get__
record.ensure_one()
File "/usr/lib/python3/dist-packages/odoo/models.py", line 4437, in ensure_one
raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: gestion.fonction(1, 2)
# My goal is to get SIMULTANEOUSLY 'EVERY EMPLOYE' from this 'gestion.fonction(1, 2)' the all in 'gestion.formation' and with DYNAMIC CODE