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

get the sum of list

By
hamza
on 5/8/16, 6:44 PM 205 views

how can i define the funtion _get_som_coef please need help

class gestion_classe(osv.osv):

_name = "gestion.classe"

_rec_name = "nomc"

_description = "Table des classes"

_columns = {

'nomc': fields.char('Nom de la classe',required=True),

'numg_ids': fields.one2many('gestion.groupe','classe_id','Groupes'),

'numm_ids': fields.one2many('gestion.matiere','classe1_id','Matieres'),

'somme_coef':fields.function(_get_sum_coef, string='Sum of Coef', type='integer'),

}

class gestion_matiere(osv.osv):

_name = "gestion.matiere"

_rec_name= "libelle"

_description = "Table des matieres"

_order = "numm asc"

_columns = {

'numm': fields.integer('Code matiére',required=True),

'libelle': fields.char('Libelle'),

'classe1_id': fields.many2one('gestion.classe','Classe',ondelete='cascade'),

'coef' : fields.integer('Coefficient matière'),

'prof_ids': fields.one2many('gestion.prof','matiere_id','Enseignants'),

'eleve_ids' :fields.one2many('gestion.note.matiere','asso1_id','Matiere'),

}

2

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 5/9/16, 1:48 AM

Hi,

Hope you are working with openerp 7, since its old api. Then you may try like this:

class gestion_classe(osv.osv):

_name = "gestion.classe"

_rec_name = "nomc"

_description = "Table des classes"

def _get_sum_coef(self, cr, uid, ids, name, args, context=None):

res = {}

for classe in self.browse(cr, uid, ids, context=context):

total_sum = 0

for matiere in classe.numm_ids:

total_sum += matiere.coef

res[classe.id] = {

'somme_coef': total_sum,

}

return res

_columns = {

'nomc': fields.char('Nom de la classe',required=True),

'numg_ids': fields.one2many('gestion.groupe','classe_id','Groupes'),

'numm_ids': fields.one2many('gestion.matiere','classe1_id','Matieres'),

'somme_coef':fields.function(_get_sum_coef, string='Sum of Coef', type='integer'),

}

Hope this helps

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

1 follower(s)

Stats

Asked: 5/8/16, 6:44 PM
Seen: 205 times
Last updated: 5/9/16, 1:48 AM