Odoo Help


how to browse a manytomany field in create method

Romuald Franck
on 11/2/13, 1:30 PM 3,375 views

I want to browse a many2many field but got this error:

File "C:\Program Files (x86)\OpenERP 7.0\Server\server\openerp\addons\schoolem\schoolem_dispense_cours.py", line 39, in create AttributeError: 'browse_record_list' object has no attribute 'heure_cours_dispense_id'

This is the code :

class schoolem_dispense_cours(osv.Model):

_name = 'schoolem.dispense_cours'
_columns = {
    'name' : fields.char('Code',required=True,help="Champ automatique"),
    'cours_id' : fields.many2one('schoolem.cours','Nom du Cour',required=True),
    'aca_id' : fields.many2one('schoolem.aca','Annee Academique',required=True),
    'enseignant_id' : fields.many2one('res.users','Enseignant',required=True),
    'salle_de_classe_id' : fields.many2one('schoolem.salle_de_classe','Salle de classe',required=True),
    'heure_cours_id' : fields.many2many('schoolem.heure_cours_dispense','schoolem_dispense_cours_heure_cours_dispense','dispense_cours_id','heure_cours_dispense_id','Heures de cour'),
    #'heure_cours_id' : fields.many2many('schoolem.heure_cours_dispense',required=True),

def create(self, cr, uid, vals, context=None):
        if not vals['heure_cours_id'][0][2]:
            raise osv.except_osv(('Erreur!'), ('Une Programmation doit avoir au moins une heure de cours!'))
        ids = self.search(cr,uid,[('aca_id','=',vals['aca_id'])])
        created_hc = []
        if ids : 
            for id in ids :
                obj_disp_crs = self.pool.get('schoolem.dispense_cours').browse(cr,uid,id)

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
Serpent Consulting Services Pvt. Ltd.
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 1/2/14, 4:40 AM


The obj_disp_crs.heure_cours_id contains many IDs, so you should refer it as a list.

Use this: created_hc += [x.heure_cours_dispense_id for x in obj_disp_crs.heure_cours_id])

If heure_cours_dispense_id is Many2one, use: created_hc += [x.heure_cours_dispense_id.id for x in obj_disp_crs.heure_cours_id])


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 11/2/13, 1:30 PM
Seen: 3375 times
Last updated: 3/16/15, 8:10 AM