[FIX] survey: fix another crashing computed field

Still due to some recent ORM changes: finding a real ID, assigning values
even in create mode with default values.

Task 2058598 (survey internal testing)
PR #36756
This commit is contained in:
Thibault Delavallée
2019-09-13 10:05:15 +00:00
parent 93c6f77799
commit e3828ec9cd
+11 -5
View File
@@ -123,7 +123,11 @@ class Survey(models.Model):
@api.depends('user_input_ids.state', 'user_input_ids.test_entry', 'user_input_ids.quizz_score', 'user_input_ids.quizz_passed')
def _compute_survey_statistic(self):
stat = dict((cid, dict(answer_count=0, answer_done_count=0, success_count=0, answer_score_avg_total=0.0)) for cid in self.ids)
default_vals = {
'answer_count': 0, 'answer_done_count': 0, 'success_count': 0,
'answer_score_avg': 0.0, 'success_ratio': 0.0
}
stat = dict((cid, dict(default_vals, answer_score_avg_total=0.0)) for cid in self.ids)
UserInput = self.env['survey.user_input']
base_domain = ['&', ('survey_id', 'in', self.ids), ('test_entry', '!=', True)]
@@ -136,11 +140,13 @@ class Survey(models.Model):
if item['quizz_passed']:
stat[item['survey_id'][0]]['success_count'] += item['__count']
for survey_id, values in stat.items():
avg_total = stat[survey_id].pop('answer_score_avg_total')
stat[survey_id]['answer_score_avg'] = avg_total / (stat[survey_id]['answer_done_count'] or 1)
stat[survey_id]['success_ratio'] = (stat[survey_id]['success_count'] / (stat[survey_id]['answer_done_count'] or 1.0))*100
for survey in self:
avg_total = stat[survey.id].pop('answer_score_avg_total')
stat[survey.id]['answer_score_avg'] = avg_total / (stat[survey.id]['answer_done_count'] or 1)
stat[survey.id]['success_ratio'] = (stat[survey.id]['success_count'] / (stat[survey.id]['answer_done_count'] or 1.0))*100
survey.update(stat[survey.id])
survey.update(stat.get(survey._origin.id, default_vals))
def _compute_survey_url(self):
""" Computes a public URL for the survey """