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

create and edit items of a one2many field through on_change method

By
Romuald Franck
on 1/6/14, 12:24 PM 2,076 views

I have this class (evaluation)

class schoolem_evaluation(osv.Model):
_name = 'schoolem.evaluation'
_columns = {
    'name' : fields.char('Evaluation',help="Champ automatique = periodeN_ExamenN_CoursX_SalleDeClasseS"),
    'aca_id' : fields.many2one('schoolem.aca','Annee Academique',required=True),
    'periode_id' : fields.many2one('schoolem.periode','Periode',required=True,help="Par exemple : trimestre01"),
    'examen_id' : fields.many2one('schoolem.examen','Examen',required=True),
    'salle_de_classe_id' : fields.many2one('schoolem.salle_de_classe','Salle de Classe',required=True),
    'cours_id' : fields.many2one('schoolem.cours','Cours',required=True),
    'note_ids' : fields.one2many('schoolem.note_evaluation','evaluation_id','Notes'),
}

and this class (note_evaluation)

 class schoolem_note_evaluation(osv.Model):
    _name = 'schoolem.note_evaluation'
    _order = 'etudiant_id'
    _columns = {
        'name' : fields.float('Note',digits=(6,2),required=True),
        'evaluation_id' : fields.many2one('schoolem.evaluation','Evaluation',),
        'etudiant_id' : fields.many2one('schoolem.etudiant','Etudiant',required=True),
        'rang' : fields.integer('Rang'),
        'observation' : fields.text('Observation'),
    }

And I would like the user to be able to generate one2many note_evaluation lines through an on_change method when selecting the value of the last field(cours_id) in the Evaluation_form; and to make that the generated lines appear directly in the view, so that he can insert the name value (note) of each note_evaluation line. And save all.

Is it possible? This is my current XML view file

<field name="cours_id"  context="{'evaluation_id': active_id, 'test': 1}" on_change="on_change_cours_id(examen_id,salle_de_classe_id,cours_id,aca_id)"/>
                    </group>
                    <notebook>
                        <page string="Inserer des notes">
                            <field nolabel="1" name="note_ids" context="{'evaluation_id': active_id}"/>
                        </page>

and this is the onchange function:

def on_change_cours_id(self,cr, uid, ids,examen_id,salle_de_classe_id,cours_id,aca_id,context=None):

    context=context or {}

    #if context is None:

     #   context = {}
            for etud_id in etudiant_ids:

                note_eval = self.pool.get('schoolem.note_evaluation')

                if not context.get('id', False): #id de l'evaluation

                    context['id'] = context.get('evaluation_id')

                eval_id = context.get('id', False)
                raise osv.except_osv(('the form!'), (context.get('active_id')))

                id = note_eval.create(cr, uid, {'name':0,'etudiant_id':etud_id,'evaluation_id':eval_id}, context=context)

With this, it the on_change method create the note_evaluation in the database but the user interface do not load them and the one2many field remain empty. I observe the note_evaluation in teh database donnot have the evaluation_id.

How to do?

solved, look at http://stackoverflow.com/questions/20954412/create-and-edit-items-of-a-one2many-field-through-on-change-method

Romuald Franck
on 1/7/14, 10:03 AM

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: 1/6/14, 12:24 PM
Seen: 2076 times
Last updated: 3/16/15, 8:10 AM