Skip to content
Permalink
Browse files

[IMP] survey: little optimization for user_input_line creation/update

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
  • Loading branch information...
mcm-odoo committed Sep 9, 2019
1 parent 67e0744 commit 16d2116b7110495f70eb7bf8c65350523240c5dc
Showing with 2 additions and 7 deletions.
  1. +2 −7 addons/survey/models/survey_user.py
@@ -253,23 +253,18 @@ def _check_answer_type(self):
if not fields_type.get(uil.answer_type, True):
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
def create(self, vals_list):
for vals in vals_list:
value_suggested = vals.get('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)

def write(self, vals):
value_suggested = vals.get('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)

@api.model

0 comments on commit 16d2116

Please sign in to comment.
You can’t perform that action at this time.