Skip to Content
Menu
This question has been flagged
2 Replies
1624 Views

when i use store= True the integer score get value 0 and when i don't use it it's okay

this is the declaration of field score

score = fields.Integer(string="score", readonly=True, compute="_onchange_calcul_score")

and this is the fonction

@api.onchange('response_id')
def _onchange_calcul_score(self):
for rec in self:
if rec.response_id:
rec.score = rec.response_id.quizz_score



Avatar
Discard

The reason that value is 0 once stored in the database is because the value hasn't been updated.

When store=False, the value is calculated on the fly. To prompt the calculated field to update you need to update the onchange/depends field. So when you change response_id the field should change if everything has been done correctly.

I would suggest exporting and importing using CSV/Excel, if you change onchange to depends, this should work.

Thanks,

Author

thank you Jack Dane

Best Answer
score = fields.Integer(string="score", readonly=True, compute="_compute_calcul_score", store=True)
@api.depends('response_id')
def _compute_calcul_score(self):
for rec in self:
rec.score = rec.response_id.quizz_score if rec.response_id else 0
Avatar
Discard
Author Best Answer

sorry but this is not the problem

the problem is when i use store=True, the value of score change to 0

Avatar
Discard