Odoo Help


Odoo9 computed fields

Laura Lee Appelgate
on 8/10/16, 1:38 PM 649 views

I'm creating a module for student management in "Odoo9", in a part of that module I want to compute the average mark that a student get in a subject like "maths".I'm tryingto achieve that using this code, but I have a problem computing the "Avg-Maths" immediately after filling "Maths-1" and "Maths-2", it can only be computed after saving the student profile.Can someone help me please realizing the issue here? and how can I fix this?

[![enter image description here][1]][1]

[1]: http://i.stack.imgur.com/LIZOE.png

#student class

class student_student(models.Model):




result_ids = fields.One2many("schoolresults.detail", "student_id", "School Results")




class schoolresults_detail(models.Model):

_name = "schoolresults.detail"

_description = "Student's results."

student_id = fields.Many2one("student.student", "Student", ondelete="cascade")

subject_id = fields.Many2one("schoolresults.subject", "Subject")

result_manual = fields.Float("Result")

result = fields.Float(compute='_compute_value',store=True)

manual = fields.Boolean(compute='_is_manual', default=False)



def _is_manual(self):

self.manual = self.subject_id.my_id



def _compute_value(self):


results = self.env['schoolresults.detail'].search([])

total = 0

for data in results:

total += data.result_manual

for data in results:

#if the subject is the average of others

if data.subject_id.my_id:

data.result = total

class schoolresults_subject(models.Model):

_name = "schoolresults.subject"

_description = "Student's subjects."

my_id = fields.Integer(default=0)

name = fields.Char("Subject")

--Ahmed M.Elmubarak--

Ahmed M.Elmubarak
On 8/11/16, 7:53 AM


Computed fields calculated after saving the record. You can use @api.onchange to calculated the average while entering the data ...

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

1 follower(s)


Asked: 8/10/16, 1:38 PM
Seen: 649 times
Last updated: 8/11/16, 7:53 AM