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)
@api.one
@api.depends('manual')
def _is_manual(self):
self.manual = self.subject_id.my_id
@api.one
@api.depends('result_manual','subject_id','subject_id.my_id')
def _compute_value(self):
self.ensure_one()
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")