Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
4050 Vizualizări

Hey i have an integer field "total_marks" against each question, in model 'survey.question' and another field "survey_marks" in model 'survey.page'. What i  want to do is to get all the values of total_marks from survey.question and add them. Then that result must go into other model in survey_marks field.


I am thinking about using computed fields. But unable to get the idea of it. Some guidance please. Thanks in advance

Imagine profil
Abandonează
Cel mai bun răspuns

Hello Abdullah,

You need to make a computed method for the field "survey_marks" in the model "survey.question" to fetch the required records of the model "survey.question" by search method with the needed domain and then add all the "total_marks "of the records and assign to the field "survey_marks".

For example:

def compute_survey_marks(self):
    records = self.env["survey.question"].search(domain)
    self.survey_marks = sum(records.mapped('total_marks'))

You can link the survey questions with survey page model to make it more reliable. Then all the sum of all the questions related to that survey page, will be assigned to survey marks.


I hope this will resolve your query.


Thanks,

Aman Prakash,

Webkul Software Private Limited

Imagine profil
Abandonează
Autor

Hey Thank you so much for replying. Just one question, do i need to loop through any of it?

Autor

def _compute_total_score(self):

records = self.env["survey.question"].search([('page_id', '=', self.id)])

self.survey_score = sum(records.mapped('total_marks'))

Hey Thank you so much its working now