Skip to content

Commit

Permalink
[IMP] survey: little optimization for user_input_line creation/update
Browse files Browse the repository at this point in the history
Before:
  The method _get_mark called Model.exists() just after calling
  Model.browse
  This process makes 2 calls to database to do almost the same thing

Now:
  Removed the method _get_mark and directly call Model.browse

FP feedback

Task 2066646
  • Loading branch information
mcm-odoo authored and tde-banana-odoo committed Sep 11, 2019
1 parent 572e8c8 commit d6dfe2e
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions addons/survey/models/survey_user.py
Expand Up @@ -253,23 +253,18 @@ def _check_answer_type(self):
if not fields_type.get(uil.answer_type, True): if not fields_type.get(uil.answer_type, True):
raise ValidationError(_('The answer must be in the right type')) raise ValidationError(_('The answer must be in the right type'))


def _get_mark(self, value_suggested):
label = self.env['survey.label'].browse(int(value_suggested))
mark = label.answer_score if label.exists() else 0.0
return mark

@api.model_create_multi @api.model_create_multi
def create(self, vals_list): def create(self, vals_list):
for vals in vals_list: for vals in vals_list:
value_suggested = vals.get('value_suggested') value_suggested = vals.get('value_suggested')
if value_suggested: if value_suggested:
vals.update({'answer_score': self._get_mark(value_suggested)}) vals.update({'answer_score': self.env['survey.label'].browse(int(value_suggested)).answer_score})
return super(SurveyUserInputLine, self).create(vals_list) return super(SurveyUserInputLine, self).create(vals_list)


def write(self, vals): def write(self, vals):
value_suggested = vals.get('value_suggested') value_suggested = vals.get('value_suggested')
if value_suggested: if value_suggested:
vals.update({'answer_score': self._get_mark(value_suggested)}) vals.update({'answer_score': self.env['survey.label'].browse(int(value_suggested)).answer_score})
return super(SurveyUserInputLine, self).write(vals) return super(SurveyUserInputLine, self).write(vals)


@api.model @api.model
Expand Down

0 comments on commit d6dfe2e

Please sign in to comment.