Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
8618 Ansichten

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)
                created_hc.append(obj_disp_crs.heure_cours_id.heure_cours_dispense_id)
Avatar
Verwerfen
Beste Antwort

Romuald,

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])

Thanks.

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
1
Feb. 24
2178
0
Juli 24
3243
0
Juli 22
60
1
Juli 22
3097
2
Dez. 23
33650