Odoo Help

Welcome!

This community 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.

0

how to browse a manytomany field in create method

By
Romuald Franck
on 11/2/13, 1:30 PM 2,238 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)
                created_hc.append(obj_disp_crs.heure_cours_id.heure_cours_dispense_id)
0

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
4341
| 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

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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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