Odoo Help


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.


Odoo9 computed fields

on 8/10/16, 1:38 PM 135 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--
| 5 3 5
--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 ...

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)


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